Search in sources :

Example 41 with Json

use of com.sequenceiq.cloudbreak.domain.json.Json in project cloudbreak by hortonworks.

the class OrchestratorRequestToOrchestratorConverter method convert.

@Override
public Orchestrator convert(OrchestratorRequest source) {
    Orchestrator orchestrator = new Orchestrator();
    orchestrator.setApiEndpoint(source.getApiEndpoint());
    orchestrator.setType(source.getType());
    Map<String, Object> params = new HashMap<>();
    if (source.getParameters() != null && !source.getParameters().isEmpty()) {
        params = source.getParameters();
    }
    try {
        orchestrator.setAttributes(new Json(params));
    } catch (JsonProcessingException e) {
        throw new BadRequestException("Invalid parameters", e);
    }
    return orchestrator;
}
Also used : HashMap(java.util.HashMap) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Json(com.sequenceiq.cloudbreak.domain.json.Json) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 42 with Json

use of com.sequenceiq.cloudbreak.domain.json.Json in project cloudbreak by hortonworks.

the class ClusterToClusterResponseConverter method convertKnox.

private void convertKnox(Cluster source, ClusterResponse clusterResponse) {
    Gateway gateway = source.getGateway();
    GatewayJson cloudGatewayJson = new GatewayJson();
    cloudGatewayJson.setEnableGateway(gateway.getEnableGateway());
    cloudGatewayJson.setTopologyName(gateway.getTopologyName());
    Json exposedJson = gateway.getExposedServices();
    if (exposedJson != null && StringUtils.isNoneEmpty(exposedJson.getValue())) {
        try {
            cloudGatewayJson.setExposedServices(exposedJson.get(ExposedServices.class).getServices());
        } catch (IOException e) {
            LOGGER.error("Failed to add exposedServices to response", e);
            throw new CloudbreakApiException("Failed to add exposedServices to response", e);
        }
    }
    cloudGatewayJson.setPath(gateway.getPath());
    cloudGatewayJson.setTokenCert(gateway.getTokenCert());
    cloudGatewayJson.setSsoProvider(gateway.getSsoProvider());
    cloudGatewayJson.setSsoType(gateway.getSsoType());
    cloudGatewayJson.setGatewayType(gateway.getGatewayType());
    clusterResponse.setGateway(cloudGatewayJson);
}
Also used : Gateway(com.sequenceiq.cloudbreak.domain.Gateway) AmbariRepoDetailsJson(com.sequenceiq.cloudbreak.api.model.AmbariRepoDetailsJson) GatewayJson(com.sequenceiq.cloudbreak.api.model.GatewayJson) Json(com.sequenceiq.cloudbreak.domain.json.Json) BlueprintInputJson(com.sequenceiq.cloudbreak.api.model.BlueprintInputJson) IOException(java.io.IOException) CloudbreakApiException(com.sequenceiq.cloudbreak.controller.CloudbreakApiException) GatewayJson(com.sequenceiq.cloudbreak.api.model.GatewayJson)

Example 43 with Json

use of com.sequenceiq.cloudbreak.domain.json.Json in project cloudbreak by hortonworks.

the class OrchestratorToOrchestratorResponseConverter method convert.

@Override
public OrchestratorResponse convert(Orchestrator source) {
    OrchestratorResponse orchestratorResponse = new OrchestratorResponse();
    orchestratorResponse.setType(source.getType());
    orchestratorResponse.setApiEndpoint(source.getApiEndpoint());
    Json attributes = source.getAttributes();
    if (attributes != null) {
        orchestratorResponse.setParameters(attributes.getMap());
    }
    return orchestratorResponse;
}
Also used : Json(com.sequenceiq.cloudbreak.domain.json.Json) OrchestratorResponse(com.sequenceiq.cloudbreak.api.model.OrchestratorResponse)

Example 44 with Json

use of com.sequenceiq.cloudbreak.domain.json.Json in project cloudbreak by hortonworks.

the class AmbariClusterService method createHDPRepoComponent.

private void createHDPRepoComponent(StackRepoDetails stackRepoDetailsUpdate, Stack stack) {
    if (stackRepoDetailsUpdate != null) {
        StackRepoDetails stackRepoDetails = clusterComponentConfigProvider.getHDPRepo(stack.getCluster().getId());
        if (stackRepoDetails == null) {
            try {
                ClusterComponent clusterComp = new ClusterComponent(ComponentType.HDP_REPO_DETAILS, new Json(stackRepoDetailsUpdate), stack.getCluster());
                clusterComponentConfigProvider.store(clusterComp);
            } catch (JsonProcessingException ignored) {
                throw new BadRequestException(String.format("HDP Repo parameters cannot be converted. %s", stackRepoDetailsUpdate));
            }
        } else {
            ClusterComponent component = clusterComponentConfigProvider.getComponent(stack.getCluster().getId(), ComponentType.HDP_REPO_DETAILS);
            stackRepoDetails.setHdpVersion(stackRepoDetailsUpdate.getHdpVersion());
            stackRepoDetails.setVerify(stackRepoDetailsUpdate.isVerify());
            stackRepoDetails.setStack(stackRepoDetailsUpdate.getStack());
            stackRepoDetails.setUtil(stackRepoDetailsUpdate.getUtil());
            stackRepoDetails.setEnableGplRepo(stackRepoDetailsUpdate.isEnableGplRepo());
            stackRepoDetails.setKnox(stackRepoDetailsUpdate.getKnox());
            try {
                component.setAttributes(new Json(stackRepoDetails));
                clusterComponentConfigProvider.store(component);
            } catch (JsonProcessingException ignored) {
                throw new BadRequestException(String.format("HDP Repo parameters cannot be converted. %s", stackRepoDetailsUpdate));
            }
        }
    }
}
Also used : StackRepoDetails(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails) ClusterComponent(com.sequenceiq.cloudbreak.domain.ClusterComponent) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) BlueprintParameterJson(com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson) UserNamePasswordJson(com.sequenceiq.cloudbreak.api.model.UserNamePasswordJson) HostGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson) Json(com.sequenceiq.cloudbreak.domain.json.Json) BlueprintInputJson(com.sequenceiq.cloudbreak.api.model.BlueprintInputJson) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 45 with Json

use of com.sequenceiq.cloudbreak.domain.json.Json in project cloudbreak by hortonworks.

the class CredentialSourceDecorator method decorate.

public Credential decorate(Credential credential, CredentialSourceRequest credentialSourceRequest, IdentityUser user) {
    if (credential == null) {
        credential = Strings.isNullOrEmpty(credentialSourceRequest.getSourceName()) ? credentialService.get(credentialSourceRequest.getSourceId()) : credentialService.get(credentialSourceRequest.getSourceName(), user.getAccount());
        if (credential == null) {
            throw new BadRequestException("Source credential does not exist!");
        } else {
            Map<String, Object> map = credential.getAttributes().getMap();
            for (Entry<String, Object> stringObjectEntry : credentialSourceRequest.getParameters().entrySet()) {
                map.put(stringObjectEntry.getKey(), stringObjectEntry.getValue().toString());
            }
            credential.setId(null);
            credential.setName(missingResourceNameGenerator.generateName(APIResourceType.CREDENTIAL));
            try {
                credential.setAttributes(new Json(map));
            } catch (JsonProcessingException ignored) {
                throw new BadRequestException("Could not create credential from source credential!");
            }
        }
    }
    return credential;
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Json(com.sequenceiq.cloudbreak.domain.json.Json) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

Json (com.sequenceiq.cloudbreak.domain.json.Json)50 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)21 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)11 Credential (com.sequenceiq.cloudbreak.domain.Credential)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 BlueprintInputJson (com.sequenceiq.cloudbreak.api.model.BlueprintInputJson)6 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)6 IOException (java.io.IOException)6 Test (org.junit.Test)6 ClusterComponent (com.sequenceiq.cloudbreak.domain.ClusterComponent)5 AmbariRepoDetailsJson (com.sequenceiq.cloudbreak.api.model.AmbariRepoDetailsJson)4 BlueprintParameterJson (com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson)4 Component (com.sequenceiq.cloudbreak.domain.Component)4 HashSet (java.util.HashSet)4 GatewayJson (com.sequenceiq.cloudbreak.api.model.GatewayJson)3 Gateway (com.sequenceiq.cloudbreak.domain.Gateway)3 AmbariStackDetailsJson (com.sequenceiq.cloudbreak.api.model.AmbariStackDetailsJson)2 GcsFileSystemConfiguration (com.sequenceiq.cloudbreak.api.model.GcsFileSystemConfiguration)2 HostGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson)2