/** * @param configId Config ID is of the form "storage/storage/3", where 3 is the storage node index. * @return The storage node index. * @throws java.lang.IllegalArgumentException If configId does not have the required form. */ public static int getStorageNodeIndex(ConfigId configId) { Matcher matcher = STORAGE_NODE_INDEX_PATTERN.matcher(configId.s()); if (!matcher.matches()) { throw new IllegalArgumentException("Unable to extract node index from config ID " + configId); } return Integer.valueOf(matcher.group(1)); }
@GET @Path("/{instanceId}/serviceStatusInfo") @Produces(MediaType.APPLICATION_JSON) public ServiceStatusInfo getServiceStatus( @PathParam("instanceId") String instanceId, @QueryParam("clusterId") String clusterIdString, @QueryParam("serviceType") String serviceTypeString, @QueryParam("configId") String configIdString) { ApplicationInstanceReference reference = parseInstanceId(instanceId); ApplicationId applicationId = OrchestratorUtil.toApplicationId(reference); if (clusterIdString == null) { throwBadRequest("Missing clusterId query parameter"); } if (serviceTypeString == null) { throwBadRequest("Missing serviceType query parameter"); } if (configIdString == null) { throwBadRequest("Missing configId query parameter"); } ClusterId clusterId = new ClusterId(clusterIdString); ServiceType serviceType = new ServiceType(serviceTypeString); ConfigId configId = new ConfigId(configIdString); return rootManager.getStatus(applicationId, clusterId, serviceType, configId); }
@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; }
/** * @param configId Must be of the form admin/cluster-controllers/2 or NAME/standalone/NAME-controllers/2, * where NAME is the name of the content cluster. NAME-controllers is also the cluster ID of * the cluster controller cluster. * @return the Cluster Controller index given its config ID. * @throws java.lang.IllegalArgumentException if the config ID is not of the proper format. */ public static int getClusterControllerIndex(ConfigId configId) { Matcher matcher = CONTROLLER_INDEX_PATTERN.matcher(configId.s()); if (!matcher.matches()) { throw new IllegalArgumentException("Unable to extract cluster controller index from config ID " + configId); } return Integer.valueOf(matcher.group(1)); }
@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); } }