summaryrefslogtreecommitdiffstats
path: root/orchestrator
diff options
context:
space:
mode:
authortoby <smorgrav@yahoo-inc.com>2016-06-17 13:09:42 +0200
committertoby <smorgrav@yahoo-inc.com>2016-06-17 13:09:42 +0200
commit65ed7f8d27200eeeb39a5316ccdda6cd11e29013 (patch)
treeac0033c694460a413025e2f956d1b75e9d318473 /orchestrator
parentcb54d6a816f6fc71307ce689fcb6b33dcff19720 (diff)
Reuse toApplictionId instead of the matchApplicationId method
Diffstat (limited to 'orchestrator')
-rw-r--r--orchestrator/src/main/java/com/yahoo/vespa/orchestrator/ApplicationIdNotFoundException.java8
-rw-r--r--orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorUtil.java27
2 files changed, 17 insertions, 18 deletions
diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/ApplicationIdNotFoundException.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/ApplicationIdNotFoundException.java
index 0e4535a3a51..f6f67ba97bc 100644
--- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/ApplicationIdNotFoundException.java
+++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/ApplicationIdNotFoundException.java
@@ -7,4 +7,12 @@ package com.yahoo.vespa.orchestrator;
* @author <a href="mailto:smorgrav@yahoo-inc.com">Toby</a>
*/
public class ApplicationIdNotFoundException extends Exception {
+
+ public ApplicationIdNotFoundException() {
+ super();
+ }
+
+ public ApplicationIdNotFoundException(String reason) {
+ super(reason);
+ }
}
diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorUtil.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorUtil.java
index 3f5df12723d..834e63a12ae 100644
--- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorUtil.java
+++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorUtil.java
@@ -115,36 +115,27 @@ public class OrchestratorUtil {
Set<ApplicationInstanceReference> appRefs = instanceLookupService.knownInstances();
List<ApplicationInstanceReference> appRefList = appRefs.stream()
- .filter(a -> matchAppInstanceAndId(a, appId))
+ .filter(a -> OrchestratorUtil.toApplicationId(a).equals(appId))
+ .filter(a -> a.equals(appId))
.collect(Collectors.toList());
- if (appRefList.size() != 1) {
- throw new ApplicationIdNotFoundException();
+ if (appRefList.size() > 1) {
+ String msg = String.format("ApplicationId '%s' was not unique but mapped to '%s", appId, appRefList);
+ throw new ApplicationIdNotFoundException(msg);
}
- return appRefList.get(0);
- }
-
- private static boolean matchAppInstanceAndId(ApplicationInstanceReference appInstanceRef, ApplicationId appId) {
- // Match tenant first
- if (!appInstanceRef.tenantId().toString().equals(appId.tenant().toString())) {
- return false;
+ if (appRefList.size() == 0) {
+ throw new ApplicationIdNotFoundException();
}
- // Match appId and InstanceId
- String[] appInstancePart = appInstanceRef.applicationInstanceId().toString().split(":");
- if (appInstancePart.length != 4) {
- throw new RuntimeException("Found inconsistent");
- }
- return appId.application().toString().equals(appInstancePart[0])
- && appId.instance().toString().equals(appInstancePart[3]);
+ return appRefList.get(0);
}
public static ApplicationId toApplicationId(ApplicationInstanceReference appRef) {
String appNameStr = appRef.toString();
String[] appNameParts = appNameStr.split(":");
- // This assumption will soon be validated in the AppRef model
+ // TODO model ApplicationInstanceReference properly and validate this there
if (appNameParts.length != 5) {
throw new IllegalArgumentException("Application reference not valid (not 5 parts): " + appRef);
}