Skip to content

Commit

Permalink
Few more null checks on token
Browse files Browse the repository at this point in the history
  • Loading branch information
zmarois committed Nov 27, 2017
1 parent f72091a commit 9859f59
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ protected List<ReplaceableAttribute> createAttributesToRegister(PriamInstance in
instance.setUpdatetime(new Date().getTime());
List<ReplaceableAttribute> attrs = new ArrayList<ReplaceableAttribute>();
attrs.add(new ReplaceableAttribute(Attributes.INSTANCE_ID, instance.getInstanceId(), false));
attrs.add(new ReplaceableAttribute(Attributes.TOKEN, instance.getToken(), true));
if (instance.getToken() != null) {
attrs.add(new ReplaceableAttribute(Attributes.TOKEN, instance.getToken(), true));
}
attrs.add(new ReplaceableAttribute(Attributes.APP_ID, instance.getApp(), true));
attrs.add(new ReplaceableAttribute(Attributes.ID, Integer.toString(instance.getId()), true));
attrs.add(new ReplaceableAttribute(Attributes.AVAILABILITY_ZONE, instance.getRac(), true));
Expand All @@ -152,7 +154,9 @@ protected List<ReplaceableAttribute> createAttributesToRegister(PriamInstance in
protected List<Attribute> createAttributesToDeRegister(PriamInstance instance) {
List<Attribute> attrs = new ArrayList<Attribute>();
attrs.add(new Attribute(Attributes.INSTANCE_ID, instance.getInstanceId()));
attrs.add(new Attribute(Attributes.TOKEN, instance.getToken()));
if (instance.getToken() != null) {
attrs.add(new Attribute(Attributes.TOKEN, instance.getToken()));
}
attrs.add(new Attribute(Attributes.APP_ID, instance.getApp()));
attrs.add(new Attribute(Attributes.ID, Integer.toString(instance.getId())));
attrs.add(new Attribute(Attributes.AVAILABILITY_ZONE, instance.getRac()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ public void execute() throws Exception {

Date startTime = Calendar.getInstance(TimeZone.getTimeZone("GMT")).getTime();
snapshotName = pathFactory.get().formatDate(startTime);
String token = instanceIdentity.getToken();
String backupIdentifier = instanceIdentity.getBackupIdentifier();

// Save start snapshot status
BackupMetadata backupMetadata = new BackupMetadata(token, startTime);
BackupMetadata backupMetadata = new BackupMetadata(backupIdentifier, startTime);
snapshotStatusMgr.start(backupMetadata);

try {
Expand Down Expand Up @@ -158,6 +158,7 @@ public Void retriableCall() throws Exception {
}.call();
}


@Override
public String getName() {
return JOBNAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,23 @@ public String getReplaceIp() {

private String findReplaceIp(List<PriamInstance> allIds, String token, String location) {
String ip = null;
for (PriamInstance ins : allIds) {
logger.info("Calling getIp on hostname[{}] and token[{}]", ins.getHostName(), token);
if (ins.getToken().equals(token) || !ins.getDC().equals(location)) { //avoid using dead instance and other regions' instances
continue;
}

try {
ip = getIp(ins.getHostName(), token);
} catch (ParseException e) {
ip = null;
}

if (ip != null) {
logger.info("Found the IP: {}", ip);
return ip;
if (token != null) {
for (PriamInstance ins : allIds) {
logger.info("Calling getIp on hostname[{}] and token[{}]", ins.getHostName(), token);
if (token.equalsIgnoreCase(ins.getToken()) || !ins.getDC().equals(location)) { //avoid using dead instance and other regions' instances
continue;
}

try {
ip = getIp(ins.getHostName(), token);
} catch (ParseException e) {
ip = null;
}

if (ip != null) {
logger.info("Found the IP: {}", ip);
return ip;
}
}
}

Expand Down

0 comments on commit 9859f59

Please sign in to comment.