Search in sources :

Example 1 with HostSelector

use of com.spotify.helios.common.descriptors.HostSelector in project helios by spotify.

the class DeploymentGroupCreateCommand method run.

@Override
int run(final Namespace options, final HeliosClient client, final PrintStream out, final boolean json, final BufferedReader stdin) throws ExecutionException, InterruptedException, IOException {
    final String name = options.getString(nameArg.getDest());
    final List<HostSelector> hostSelectors = Utils.parseHostSelectors(options, hostSelectorsArg);
    final boolean quiet = options.getBoolean(quietArg.getDest());
    final DeploymentGroup deploymentGroup = DeploymentGroup.newBuilder().setName(name).setHostSelectors(hostSelectors).build();
    if (!quiet && !json) {
        out.println("Creating deployment group: " + deploymentGroup.toJsonString());
    }
    final CreateDeploymentGroupResponse status = client.createDeploymentGroup(deploymentGroup).get();
    if (status == null) {
        throw new RuntimeException("The Helios master could not create a deployment group.");
    }
    if (status.getStatus() != CreateDeploymentGroupResponse.Status.CONFLICT) {
        out.println(status.toJsonString());
        return 0;
    } else {
        if (!quiet && !json) {
            out.println("Failed: " + status);
        } else if (json) {
            out.println(status.toJsonString());
        }
        return 1;
    }
}
Also used : CreateDeploymentGroupResponse(com.spotify.helios.common.protocol.CreateDeploymentGroupResponse) HostSelector(com.spotify.helios.common.descriptors.HostSelector) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup)

Example 2 with HostSelector

use of com.spotify.helios.common.descriptors.HostSelector in project helios by spotify.

the class DeploymentGroupStatusCommand method run0.

static int run0(final HeliosClient client, final PrintStream out, final boolean json, final String name, final boolean full) throws ExecutionException, InterruptedException {
    final DeploymentGroupStatusResponse status = client.deploymentGroupStatus(name).get();
    if (status == null) {
        if (json) {
            final Map<String, Object> output = Maps.newHashMap();
            output.put("status", "DEPLOYMENT_GROUP_NOT_FOUND");
            out.print(Json.asStringUnchecked(output));
        } else {
            out.printf("Unknown deployment group: %s%n", name);
        }
        return 1;
    }
    if (json) {
        out.println(Json.asPrettyStringUnchecked(status));
    } else {
        final JobId jobId = status.getDeploymentGroup().getJobId();
        final String error = status.getError();
        final List<HostSelector> hostSelectors = status.getDeploymentGroup().getHostSelectors();
        out.printf("Name: %s%n", name);
        out.printf("Job Id: %s%n", full ? jobId : (jobId == null ? null : jobId.toShortString()));
        out.printf("Status: %s%n", status.getStatus());
        out.printf("Host selectors:%n");
        for (final HostSelector hostSelector : hostSelectors) {
            out.printf("  %s%n", hostSelector.toPrettyString());
        }
        if (!Strings.isNullOrEmpty(error)) {
            out.printf("Error: %s%n", error);
        }
        out.printf("%n");
        printTable(out, jobId, status.getHostStatuses(), full);
    }
    return 0;
}
Also used : HostSelector(com.spotify.helios.common.descriptors.HostSelector) DeploymentGroupStatusResponse(com.spotify.helios.common.protocol.DeploymentGroupStatusResponse) JobId(com.spotify.helios.common.descriptors.JobId)

Example 3 with HostSelector

use of com.spotify.helios.common.descriptors.HostSelector in project helios by spotify.

the class DeploymentGroupInspectCommand method run.

@Override
int run(final Namespace options, final HeliosClient client, final PrintStream out, final boolean json, final BufferedReader stdin) throws ExecutionException, InterruptedException, IOException {
    final String name = options.getString(nameArg.getDest());
    final DeploymentGroup deploymentGroup = client.deploymentGroup(name).get();
    if (deploymentGroup == null) {
        if (json) {
            final Map<String, Object> output = Maps.newHashMap();
            output.put("status", "DEPLOYMENT_GROUP_NOT_FOUND");
            out.print(Json.asStringUnchecked(output));
        } else {
            out.printf("Unknown deployment group: %s%n", name);
        }
        return 1;
    }
    if (json) {
        out.println(Json.asPrettyStringUnchecked(deploymentGroup));
    } else {
        out.printf("Name: %s%n", deploymentGroup.getName());
        out.printf("Host selectors:%n");
        for (final HostSelector hostSelector : deploymentGroup.getHostSelectors()) {
            out.printf("  %s%n", hostSelector.toPrettyString());
        }
        out.printf("Job: %s%n", deploymentGroup.getJobId());
        if (deploymentGroup.getRollingUpdateReason() != null) {
            out.printf("Rolling update reason: %s%n", deploymentGroup.getRollingUpdateReason());
        }
        final RolloutOptions rolloutOptions = deploymentGroup.getRolloutOptions();
        if (rolloutOptions != null) {
            out.printf("Rollout options:%n");
            out.printf("  Migrate: %s%n", rolloutOptions.getMigrate());
            out.printf("  Overlap: %s%n", rolloutOptions.getOverlap());
            out.printf("  Parallelism: %d%n", rolloutOptions.getParallelism());
            out.printf("  Timeout: %d%n", rolloutOptions.getTimeout());
            if (!isNullOrEmpty(rolloutOptions.getToken())) {
                out.printf("  Token: %s%n", rolloutOptions.getToken());
            }
            out.printf("  Ignore failures: %b%n", rolloutOptions.getIgnoreFailures());
        }
    }
    return 0;
}
Also used : RolloutOptions(com.spotify.helios.common.descriptors.RolloutOptions) HostSelector(com.spotify.helios.common.descriptors.HostSelector) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup)

Example 4 with HostSelector

use of com.spotify.helios.common.descriptors.HostSelector in project helios by spotify.

the class Utils method parseHostSelectors.

public static List<HostSelector> parseHostSelectors(final Namespace namespace, final Argument arg) {
    final List<List<String>> args = namespace.getList(arg.getDest());
    final List<HostSelector> ret = Lists.newArrayList();
    if (args != null) {
        for (final List<String> group : args) {
            for (final String s : group) {
                final HostSelector hostSelector = HostSelector.parse(s);
                if (hostSelector == null) {
                    throw new IllegalArgumentException(format("Bad host selector expression: '%s'", s));
                }
                ret.add(hostSelector);
            }
        }
    }
    return ret;
}
Also used : HostSelector(com.spotify.helios.common.descriptors.HostSelector) List(java.util.List)

Example 5 with HostSelector

use of com.spotify.helios.common.descriptors.HostSelector in project helios by spotify.

the class HostsResource method list.

/**
 * Returns the list of hostnames of known hosts/agents.
 *
 * @return The list of hostnames.
 */
@GET
@Produces(APPLICATION_JSON)
@Timed
@ExceptionMetered
public List<String> list(@QueryParam("namePattern") final String namePattern, @QueryParam("selector") final List<String> hostSelectors) {
    List<String> hosts = namePattern == null ? model.listHosts() : model.listHosts(namePattern);
    if (!hostSelectors.isEmpty()) {
        // check that all supplied selectors are parseable/valid
        final List<HostSelector> selectors = hostSelectors.stream().map(selectorStr -> {
            final HostSelector parsed = HostSelector.parse(selectorStr);
            if (parsed == null) {
                throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity("Invalid host selector: " + selectorStr).build());
            }
            return parsed;
        }).collect(Collectors.toList());
        final Map<String, Map<String, String>> hostsAndLabels = getLabels(hosts);
        final HostMatcher matcher = new HostMatcher(hostsAndLabels);
        hosts = matcher.getMatchingHosts(selectors);
    }
    return hosts;
}
Also used : Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) SetGoalResponse(com.spotify.helios.common.protocol.SetGoalResponse) HostRegisterResponse(com.spotify.helios.common.protocol.HostRegisterResponse) Valid(javax.validation.Valid) QueryParam(javax.ws.rs.QueryParam) Optional(com.google.common.base.Optional) JobUndeployResponse(com.spotify.helios.common.protocol.JobUndeployResponse) Map(java.util.Map) INVALID_ID(com.spotify.helios.common.protocol.JobUndeployResponse.Status.INVALID_ID) Deployment(com.spotify.helios.common.descriptors.Deployment) DefaultValue(javax.ws.rs.DefaultValue) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) HostStillInUseException(com.spotify.helios.master.HostStillInUseException) JobDeployResponse(com.spotify.helios.common.protocol.JobDeployResponse) DELETE(javax.ws.rs.DELETE) HostMatcher(com.spotify.helios.master.HostMatcher) Responses.notFound(com.spotify.helios.master.http.Responses.notFound) JobDoesNotExistException(com.spotify.helios.master.JobDoesNotExistException) FORBIDDEN(com.spotify.helios.common.protocol.JobUndeployResponse.Status.FORBIDDEN) JOB_NOT_FOUND(com.spotify.helios.common.protocol.JobUndeployResponse.Status.JOB_NOT_FOUND) Collectors(java.util.stream.Collectors) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) Response(javax.ws.rs.core.Response) JobPortAllocationConflictException(com.spotify.helios.master.JobPortAllocationConflictException) WebApplicationException(javax.ws.rs.WebApplicationException) Responses.badRequest(com.spotify.helios.master.http.Responses.badRequest) JobId(com.spotify.helios.common.descriptors.JobId) PathParam(javax.ws.rs.PathParam) HOST_NOT_FOUND(com.spotify.helios.common.protocol.JobUndeployResponse.Status.HOST_NOT_FOUND) GET(javax.ws.rs.GET) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) OK(com.spotify.helios.common.protocol.JobUndeployResponse.Status.OK) PATCH(com.spotify.helios.master.http.PATCH) Function(java.util.function.Function) Responses.forbidden(com.spotify.helios.master.http.Responses.forbidden) HostSelector(com.spotify.helios.common.descriptors.HostSelector) EMPTY_TOKEN(com.spotify.helios.common.descriptors.Job.EMPTY_TOKEN) HostStatus(com.spotify.helios.common.descriptors.HostStatus) HostNotFoundException(com.spotify.helios.master.HostNotFoundException) JobAlreadyDeployedException(com.spotify.helios.master.JobAlreadyDeployedException) MasterModel(com.spotify.helios.master.MasterModel) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) HostDeregisterResponse(com.spotify.helios.common.protocol.HostDeregisterResponse) Maps(com.google.common.collect.Maps) TokenVerificationException(com.spotify.helios.master.TokenVerificationException) PUT(javax.ws.rs.PUT) JobNotDeployedException(com.spotify.helios.master.JobNotDeployedException) WebApplicationException(javax.ws.rs.WebApplicationException) HostSelector(com.spotify.helios.common.descriptors.HostSelector) Map(java.util.Map) HostMatcher(com.spotify.helios.master.HostMatcher) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Aggregations

HostSelector (com.spotify.helios.common.descriptors.HostSelector)6 DeploymentGroup (com.spotify.helios.common.descriptors.DeploymentGroup)2 JobId (com.spotify.helios.common.descriptors.JobId)2 List (java.util.List)2 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)1 Timed (com.codahale.metrics.annotation.Timed)1 Optional (com.google.common.base.Optional)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Maps (com.google.common.collect.Maps)1 Deployment (com.spotify.helios.common.descriptors.Deployment)1 HostStatus (com.spotify.helios.common.descriptors.HostStatus)1 EMPTY_TOKEN (com.spotify.helios.common.descriptors.Job.EMPTY_TOKEN)1 RolloutOptions (com.spotify.helios.common.descriptors.RolloutOptions)1 CreateDeploymentGroupResponse (com.spotify.helios.common.protocol.CreateDeploymentGroupResponse)1 DeploymentGroupStatusResponse (com.spotify.helios.common.protocol.DeploymentGroupStatusResponse)1 HostDeregisterResponse (com.spotify.helios.common.protocol.HostDeregisterResponse)1 HostRegisterResponse (com.spotify.helios.common.protocol.HostRegisterResponse)1 JobDeployResponse (com.spotify.helios.common.protocol.JobDeployResponse)1 JobUndeployResponse (com.spotify.helios.common.protocol.JobUndeployResponse)1 FORBIDDEN (com.spotify.helios.common.protocol.JobUndeployResponse.Status.FORBIDDEN)1