@JsonProperty("reference") public ApplicationInstanceReference reference() { return new ApplicationInstanceReference(tenantId, applicationInstanceId); }
@JsonValue @Override public String toString() { return asString(); }
private static String applicationInstancePath(ApplicationInstanceReference applicationInstanceReference) { return HOST_STATUS_BASE_PATH + '/' + applicationInstanceReference.tenantId() + ":" + applicationInstanceReference.applicationInstanceId(); }
/** Returns an ApplicationInstanceReference constructed from the serialized format used in the REST API. */ public static ApplicationInstanceReference parseAppInstanceReference(String restFormat) { if (restFormat == null) { throw new IllegalArgumentException("Could not construct instance id from null string"); } Matcher matcher = APPLICATION_INSTANCE_REFERENCE_REST_FORMAT_PATTERN.matcher(restFormat); if (!matcher.matches()) { throw new IllegalArgumentException("Could not construct instance id from string \"" + restFormat +"\""); } TenantId tenantId = new TenantId(matcher.group(1)); ApplicationInstanceId applicationInstanceId = new ApplicationInstanceId(matcher.group(2)); return new ApplicationInstanceReference(tenantId, applicationInstanceId); }
private static int compareNodeGroupsForSuspend(NodeGroup leftNodeGroup, NodeGroup rightNodeGroup) { ApplicationInstanceReference leftApplicationReference = leftNodeGroup.getApplicationReference(); ApplicationInstanceReference rightApplicationReference = rightNodeGroup.getApplicationReference(); // ApplicationInstanceReference.toString() is e.g. "hosted-vespa:routing:dev:some-region:default" return leftApplicationReference.asString().compareTo(rightApplicationReference.asString()); }
public static String toRestApiFormat(ApplicationInstanceReference applicationInstanceReference) { return applicationInstanceReference.tenantId() + ":" + applicationInstanceReference.applicationInstanceId(); }
@Override public Map<ApplicationInstanceReference, ApplicationInstance> getAllApplicationInstances() { // Convert apps information to the response payload to return Map<ApplicationInstanceReference, ApplicationInstance> status = new HashMap<>(); for (Map.Entry<ApplicationId, MockDeployer.ApplicationContext> app : apps.entrySet()) { Set<ServiceInstance> serviceInstances = new HashSet<>(); for (Node node : nodeRepository.getNodes(app.getValue().id(), Node.State.active)) { serviceInstances.add(new ServiceInstance(new ConfigId("configid"), new HostName(node.hostname()), getHostStatus(node.hostname()))); } Set<ServiceCluster> serviceClusters = new HashSet<>(); serviceClusters.add(new ServiceCluster(new ClusterId(app.getValue().clusterContexts().get(0).cluster().id().value()), new ServiceType("serviceType"), serviceInstances)); TenantId tenantId = new TenantId(app.getKey().tenant().value()); ApplicationInstanceId applicationInstanceId = new ApplicationInstanceId(app.getKey().application().value()); status.put(new ApplicationInstanceReference(tenantId, applicationInstanceId), new ApplicationInstance(tenantId, applicationInstanceId, serviceClusters)); } return status; }
@Override public void setApplicationInstanceStatus(ApplicationInstanceStatus applicationInstanceStatus) { if (probe) return; log.log(LogLevel.INFO, "Setting app " + applicationInstanceReference.asString() + " to status " + applicationInstanceStatus); String path = applicationInstanceSuspendedPath(applicationInstanceReference); try { switch (applicationInstanceStatus) { case NO_REMARKS: deleteNode_ignoreNoNodeException(path, "Instance is already in state NO_REMARKS, path = " + path); break; case ALLOWED_TO_BE_DOWN: createNode_ignoreNodeExistsException(path, "Instance is already in state ALLOWED_TO_BE_DOWN, path = " + path); break; } } catch (Exception e) { throw new RuntimeException(e); } }
public static ApplicationId toApplicationId(ApplicationInstanceReference appRef) { String appNameStr = appRef.asString(); String[] appNameParts = appNameStr.split(":"); // Env, region and instance seems to be optional due to the hardcoded config server app // Assume here that first two are tenant and application name. if (appNameParts.length == 2) { return ApplicationId.from(TenantName.from(appNameParts[0]), ApplicationName.from(appNameParts[1]), InstanceName.defaultName()); } // Other normal application should have 5 parts. if (appNameParts.length != 5) { throw new IllegalArgumentException("Application reference not valid (not 5 parts): " + appRef); } return ApplicationId.from(TenantName.from(appNameParts[0]), ApplicationName.from(appNameParts[1]), InstanceName.from(appNameParts[4])); }
@Override public GetHostResponse getHost(String hostNameString) { HostName hostName = new HostName(hostNameString); try { Host host = orchestrator.getHost(hostName); URI applicationUri = uriInfo.getBaseUriBuilder() .path(InstanceResource.class) .path(host.getApplicationInstanceReference().asString()) .build(); List<HostService> hostServices = host.getServiceInstances().stream() .map(serviceInstance -> new HostService( serviceInstance.getServiceCluster().clusterId().s(), serviceInstance.getServiceCluster().serviceType().s(), serviceInstance.configId().s(), serviceInstance.serviceStatus().name())) .collect(Collectors.toList()); return new GetHostResponse( host.getHostName().s(), host.getHostStatus().name(), applicationUri.toString(), hostServices); } catch (UncheckedTimeoutException e) { log.log(LogLevel.INFO, "Failed to get host " + hostName + ": " + e.getMessage()); throw webExceptionFromTimeout("getHost", hostName, e); } catch (HostNameNotFoundException e) { log.log(LogLevel.INFO, "Host not found: " + hostName); throw new NotFoundException(e); } }
"application " + applicationInstance.reference().asString() + ", host " + hostName() + ", cluster name " + clusterId + " has been set to " + wantedNodeState; logger.log(LogLevel.INFO, "Storage node " + nodeIndex + " in cluster " + clusterId + " application " + applicationInstance.reference().asString() + " on host " + hostName() + logSuffix);