Skip to content
This repository has been archived by the owner on Jul 7, 2020. It is now read-only.

Alias #267

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

Alias #267

wants to merge 16 commits into from

Conversation

satang500
Copy link
Contributor

No description provided.

public static final String ALIAS_PATH = "/query/alias";
private final SpawnDataStore spawnDataStore;
private final HashMap<String, List<String>> alias2jobs;
private final HashMap<String, String> job2alias;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use a BiMap? That's cleaner IMO.

public AliasManagerImpl(SpawnDataStore spawnDataStore) throws Exception {
this.spawnDataStore = spawnDataStore;
this.mapLock = new ReentrantLock();
this.mapper = new ObjectMapper();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be declared statically.

alias2jobs.put(alias, jobs);
job2alias.put(jobs.get(0), alias);
StringWriter sw = new StringWriter();
mapper.writeValue(sw, jobs);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use writeValueAsString(jobs) you wont need a StringWriter

try {
updateAlias(alias, this.spawnDataStore.getChild(ALIAS_PATH, alias));
} catch (ExecutionException e) {
log.warn("Failed to refresh alias: {}", alias, e);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why isn't this an error?

} catch (ExecutionException e) {
log.warn("Failed to refresh alias: {}", alias, e);
} catch (Exception e) {
log.error("",e);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"" isn't super useful for debugging. Something like Unexpected error refreshing alias <alias> would be better.

}
List<String> jobs = decodeAliases(data);
if (jobs.isEmpty()) {
log.warn("no jobs for alias {}, ignoring {}", alias, alias);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignoring alias {} since there are no jobs or something would avoid the redundant alias log entry.

@VisibleForTesting
protected List<String> decodeAliases(@Nonnull Object data) {
try {
return mapper.readValue(data.toString(), new TypeReference<List<String>>() {});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is data always a string here? If so why is it an object paramater?

* @param job The job to test
* @param alias The alias to check
*/
private void checkAlias(String job, String alias) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method also has unclear side effects since it removes job from job2alias when the method name is called checkAlias

* @param jobid The jobId to check
* @return One of the aliases for that job
*/
public String getLikelyAlias(String jobid) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why likely alias? Wouldn't this be the alias?

}
} finally {
mapLock.unlock();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you copy the maps first? What happens if the deleteChild call below fails? You now have a bad state.

@satang500 satang500 changed the title Alias [WIP] Alias Aug 15, 2017
public void deleteAlias(String alias) {
mapCache.remove(alias);
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, There is weird symbol right next to right curly bract in line 104. Cannot remove it from PR, but it's ok in source code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you mouse over the 'weird symbol' it will tell you what it means. Please try this.

@satang500 satang500 changed the title [WIP] Alias Alias Aug 15, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants