Search in sources :

Example 6 with Measure

use of com.sequenceiq.cloudbreak.aspect.Measure in project cloudbreak by hortonworks.

the class SaltConnector method members.

@Measure(SaltConnector.class)
@Retryable(value = ClusterProxyWebApplicationException.class, backoff = @Backoff(delay = 1000))
public Map<String, String> members(List<String> privateIps) throws CloudbreakOrchestratorFailedException {
    Map<String, List<String>> clients = singletonMap("clients", privateIps);
    Response response = postSignedJsonSaltRequest(BOOT_HOSTNAME_ENDPOINT, clients);
    GenericResponses responses = JaxRSUtil.response(response, GenericResponses.class);
    List<GenericResponse> failedResponses = responses.getResponses().stream().filter(genericResponse -> !ACCEPTED_STATUSES.contains(genericResponse.getStatusCode())).collect(Collectors.toList());
    if (!failedResponses.isEmpty()) {
        failedResponseErrorLog(failedResponses);
        String nodeErrors = failedResponses.stream().map(gr -> gr.getAddress() + ": " + gr.getErrorText()).collect(Collectors.joining(","));
        throw new CloudbreakOrchestratorFailedException("Hostname resolution failed for nodes: " + nodeErrors);
    }
    return responses.getResponses().stream().collect(Collectors.toMap(GenericResponse::getAddress, GenericResponse::getStatus));
}
Also used : GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Response(javax.ws.rs.core.Response) FingerprintsResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintsResponse) Arrays(java.util.Arrays) Target(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.Target) LoggerFactory(org.slf4j.LoggerFactory) HttpStatus(org.apache.http.HttpStatus) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) Measure(com.sequenceiq.cloudbreak.aspect.Measure) MediaType(javax.ws.rs.core.MediaType) JaxRSUtil(com.sequenceiq.cloudbreak.util.JaxRSUtil) ByteArrayInputStream(java.io.ByteArrayInputStream) SaltErrorResolver(com.sequenceiq.cloudbreak.orchestrator.salt.SaltErrorResolver) Map(java.util.Map) SaltAction(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) BOOT_HOSTNAME_ENDPOINT(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltEndpoint.BOOT_HOSTNAME_ENDPOINT) SetProxyTimeoutFeature(com.sequenceiq.cloudbreak.client.SetProxyTimeoutFeature) Collection(java.util.Collection) ClientTracingFeature(io.opentracing.contrib.jaxrs2.client.ClientTracingFeature) Invocation(javax.ws.rs.client.Invocation) Collectors(java.util.stream.Collectors) Entity(javax.ws.rs.client.Entity) Backoff(org.springframework.retry.annotation.Backoff) List(java.util.List) Response(javax.ws.rs.core.Response) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) StreamDataBodyPart(org.glassfish.jersey.media.multipart.file.StreamDataBodyPart) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Optional(java.util.Optional) MultiPart(org.glassfish.jersey.media.multipart.MultiPart) Form(javax.ws.rs.core.Form) Pillar(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Pillar) Client(javax.ws.rs.client.Client) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) BOOT_FINGERPRINT_DISTRIBUTE(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltEndpoint.BOOT_FINGERPRINT_DISTRIBUTE) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) Collections.singletonMap(java.util.Collections.singletonMap) Retryable(org.springframework.retry.annotation.Retryable) AnonymizerUtil.anonymize(com.sequenceiq.cloudbreak.common.anonymizer.AnonymizerUtil.anonymize) FingerprintRequest(com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintRequest) Logger(org.slf4j.Logger) Tracer(io.opentracing.Tracer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) DisableProxyAuthFeature(com.sequenceiq.cloudbreak.client.DisableProxyAuthFeature) ClusterProxyWebApplicationException(com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyWebApplicationException) FingerprintsResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintsResponse) Closeable(java.io.Closeable) PkiUtil(com.sequenceiq.cloudbreak.certificate.PkiUtil) RestClientUtil(com.sequenceiq.cloudbreak.client.RestClientUtil) WebTarget(javax.ws.rs.client.WebTarget) HttpAuthenticationFeature(org.glassfish.jersey.client.authentication.HttpAuthenticationFeature) Collections(java.util.Collections) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) List(java.util.List) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) Retryable(org.springframework.retry.annotation.Retryable) Measure(com.sequenceiq.cloudbreak.aspect.Measure)

Example 7 with Measure

use of com.sequenceiq.cloudbreak.aspect.Measure in project cloudbreak by hortonworks.

the class SaltConnector method run.

@Measure(SaltConnector.class)
@Retryable(value = ClusterProxyWebApplicationException.class, backoff = @Backoff(delay = 1000))
public <T> T run(Target<String> target, String fun, SaltClientType clientType, Class<T> clazz, Long timeout, String... arg) {
    Form form = new Form();
    form = addAuth(form).param("fun", fun).param("client", clientType.getType());
    if (target != null) {
        form = form.param("tgt", target.getTarget()).param("tgt_type", target.getType());
    }
    if (timeout != null) {
        form = form.param("t", timeout.toString());
    }
    if ("state.show_sls".equals(fun)) {
        form.param("full_return", "True");
    }
    if (arg != null) {
        if (clientType.equals(SaltClientType.LOCAL) || clientType.equals(SaltClientType.LOCAL_ASYNC)) {
            for (String a : arg) {
                form.param("arg", a);
            }
        } else {
            for (int i = 0; i < arg.length - 1; i += 2) {
                form.param(arg[i], arg[i + 1]);
            }
        }
    }
    Response response = endpointInvocation(SaltEndpoint.SALT_RUN.getContextPath(), toJson(form.asMap()).getBytes()).post(Entity.form(form));
    T responseEntity = JaxRSUtil.response(response, clazz);
    try {
        LOGGER.debug("Salt run has been executed. fun: [{}],  parsed response: [{}]", fun, anonymize(JsonUtil.writeValueAsString(responseEntity)));
    } catch (JsonProcessingException e) {
        LOGGER.error("Can not read response from salt", e);
    }
    return responseEntity;
}
Also used : GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Response(javax.ws.rs.core.Response) FingerprintsResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintsResponse) BOOT_HOSTNAME_ENDPOINT(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltEndpoint.BOOT_HOSTNAME_ENDPOINT) Form(javax.ws.rs.core.Form) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Retryable(org.springframework.retry.annotation.Retryable) Measure(com.sequenceiq.cloudbreak.aspect.Measure)

Example 8 with Measure

use of com.sequenceiq.cloudbreak.aspect.Measure in project cloudbreak by hortonworks.

the class SaltConnector method action.

@Measure(SaltConnector.class)
@Retryable(value = ClusterProxyWebApplicationException.class, backoff = @Backoff(delay = 1000))
public GenericResponses action(SaltAction saltAction) {
    Response response = postSignedJsonSaltRequest(SaltEndpoint.BOOT_ACTION_DISTRIBUTE, saltAction);
    GenericResponses responseEntity = JaxRSUtil.response(response, GenericResponses.class);
    LOGGER.debug("SaltBoot. SaltAction response: {}", responseEntity);
    return responseEntity;
}
Also used : GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Response(javax.ws.rs.core.Response) FingerprintsResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintsResponse) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) Retryable(org.springframework.retry.annotation.Retryable) Measure(com.sequenceiq.cloudbreak.aspect.Measure)

Example 9 with Measure

use of com.sequenceiq.cloudbreak.aspect.Measure in project cloudbreak by hortonworks.

the class SaltConnector method health.

@Measure(SaltConnector.class)
@Retryable(value = ClusterProxyWebApplicationException.class, backoff = @Backoff(delay = 1000))
public GenericResponse health() {
    LOGGER.debug("Sending request to salt endpoint {}", SaltEndpoint.BOOT_HEALTH.getContextPath());
    Response response = saltTarget.path(SaltEndpoint.BOOT_HEALTH.getContextPath()).request().get();
    GenericResponse responseEntity = JaxRSUtil.response(response, GenericResponse.class);
    LOGGER.debug("SaltBoot. Health response: {}", responseEntity);
    return responseEntity;
}
Also used : GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Response(javax.ws.rs.core.Response) FingerprintsResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintsResponse) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Retryable(org.springframework.retry.annotation.Retryable) Measure(com.sequenceiq.cloudbreak.aspect.Measure)

Example 10 with Measure

use of com.sequenceiq.cloudbreak.aspect.Measure in project cloudbreak by hortonworks.

the class ImageService method create.

@Measure(ImageService.class)
public Set<Component> create(Stack stack, StatedImage imgFromCatalog) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    String region = stack.getRegion();
    String cloudPlatform = stack.getCloudPlatform();
    ImageCatalogPlatform platformString = platformStringTransformer.getPlatformStringForImageCatalog(cloudPlatform, stack.getPlatformVariant());
    LOGGER.debug("Determined image from catalog: {}", imgFromCatalog);
    String imageName = determineImageName(cloudPlatform, platformString, region, imgFromCatalog.getImage());
    LOGGER.debug("Selected VM image for CloudPlatform '{}' and region '{}' is: {} from: {} image catalog", platformString, region, imageName, imgFromCatalog.getImageCatalogUrl());
    Set<Component> components = getComponents(stack, Map.of(), imgFromCatalog, EnumSet.of(IMAGE, CDH_PRODUCT_DETAILS, CM_REPO_DETAILS));
    componentConfigProviderService.store(components);
    return components;
}
Also used : ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) Component(com.sequenceiq.cloudbreak.domain.stack.Component) Measure(com.sequenceiq.cloudbreak.aspect.Measure)

Aggregations

Measure (com.sequenceiq.cloudbreak.aspect.Measure)15 Retryable (org.springframework.retry.annotation.Retryable)7 GenericResponse (com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse)6 FingerprintsResponse (com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintsResponse)6 Response (javax.ws.rs.core.Response)6 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)4 GenericResponses (com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses)3 BOOT_HOSTNAME_ENDPOINT (com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltEndpoint.BOOT_HOSTNAME_ENDPOINT)3 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)3 Form (javax.ws.rs.core.Form)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)2 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)2 Component (com.sequenceiq.cloudbreak.domain.stack.Component)2 ImageCatalogPlatform (com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform)2 Benchmark.multiCheckedMeasure (com.sequenceiq.cloudbreak.util.Benchmark.multiCheckedMeasure)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 PkiUtil (com.sequenceiq.cloudbreak.certificate.PkiUtil)1 DisableProxyAuthFeature (com.sequenceiq.cloudbreak.client.DisableProxyAuthFeature)1 RestClientUtil (com.sequenceiq.cloudbreak.client.RestClientUtil)1