public List<String> getMatchingHosts(final DeploymentGroup deploymentGroup) { final List<HostSelector> selectors = deploymentGroup.getHostSelectors(); if (selectors == null || selectors.isEmpty()) { log.error("skipping deployment group with no host selectors: " + deploymentGroup.getName()); return emptyList(); } return getMatchingHosts(selectors); }
@POST @Produces(APPLICATION_JSON) @Timed @ExceptionMetered public Response createDeploymentGroup(@Valid final DeploymentGroup deploymentGroup) { try { model.addDeploymentGroup(deploymentGroup); return Response.ok(CREATED_RESPONSE).build(); } catch (DeploymentGroupExistsException ignored) { final DeploymentGroup existing; try { existing = model.getDeploymentGroup(deploymentGroup.getName()); } catch (DeploymentGroupDoesNotExistException e) { // Edge condition: There's a race where someone can potentially remove the deployment-group // while this operation is in progress. This should be very rare. If it does happen, // return 500. return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } if (!Objects.equals(existing.getHostSelectors(), deploymentGroup.getHostSelectors())) { return Response.ok(DEPLOYMENT_GROUP_ALREADY_EXISTS_RESPONSE).build(); } return Response.ok(NOT_MODIFIED_RESPONSE).build(); } }
final JobId jobId = status.getDeploymentGroup().getJobId(); final String error = status.getError(); final List<HostSelector> hostSelectors = status.getDeploymentGroup().getHostSelectors();
out.printf("Name: %s%n", deploymentGroup.getName()); out.printf("Host selectors:%n"); for (final HostSelector hostSelector : deploymentGroup.getHostSelectors()) { out.printf(" %s%n", hostSelector.toPrettyString());
public List<String> getMatchingHosts(final DeploymentGroup deploymentGroup) { final List<String> matchingHosts = Lists.newArrayList(); if ((deploymentGroup.getHostSelectors() == null) || deploymentGroup.getHostSelectors().isEmpty()) { log.error("skipping deployment group with no host selectors: " + deploymentGroup.getName()); return emptyList(); } // determine the hosts that match the current deployment group hostLoop: for (final Map.Entry<String, Map<String, String>> entry : hostsAndLabels.entrySet()) { final String host = entry.getKey(); final Map<String, String> hostLabels = entry.getValue(); for (final HostSelector hostSelector : deploymentGroup.getHostSelectors()) { final String key = hostSelector.getLabel(); if (!hostLabels.containsKey(key)) { continue hostLoop; } final String hostValue = hostLabels.get(key); if (!hostSelector.matches(hostValue)) { continue hostLoop; } } matchingHosts.add(host); } Collections.sort(matchingHosts, new AlphaNumericComparator(Locale.ENGLISH)); return ImmutableList.copyOf(matchingHosts); } }
@POST @Produces(APPLICATION_JSON) @Timed @ExceptionMetered public Response createDeploymentGroup(@Valid final DeploymentGroup deploymentGroup) { try { model.addDeploymentGroup(deploymentGroup); return Response.ok(CREATED_RESPONSE).build(); } catch (DeploymentGroupExistsException ignored) { final DeploymentGroup existing; try { existing = model.getDeploymentGroup(deploymentGroup.getName()); } catch (DeploymentGroupDoesNotExistException e) { // Edge condition: There's a race where someone can potentially remove the deployment-group // while this operation is in progress. This should be very rare. If it does happen, // return 500. return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } if (!Objects.equals(existing.getHostSelectors(), deploymentGroup.getHostSelectors())) { return Response.ok(DEPLOYMENT_GROUP_ALREADY_EXISTS_RESPONSE).build(); } return Response.ok(NOT_MODIFIED_RESPONSE).build(); } }
out.printf("Name: %s%n", deploymentGroup.getName()); out.printf("Host selectors:%n"); for (final HostSelector hostSelector : deploymentGroup.getHostSelectors()) { out.printf(" %s%n", hostSelector.toPrettyString());
final JobId jobId = status.getDeploymentGroup().getJobId(); final String error = status.getError(); final List<HostSelector> hostSelectors = status.getDeploymentGroup().getHostSelectors();