use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class ContainerConfigService method create.
private Component create(Stack stack, DockerContainer dc) throws CloudbreakException {
try {
ContainerConfig config;
ContainerOrchestrator orchestrator = containerOrchestratorResolver.get(stack.getOrchestrator().getType());
Map<String, String> customContainerConfig = getCustomContainerConfig(stack);
Optional<String> customContainerName = Optional.ofNullable(customContainerConfig.get(dc.name()));
Optional<String> customQueue = getCustomQueue(stack);
switch(dc) {
case AMBARI_SERVER:
config = new Builder(orchestrator.ambariServerContainer(customContainerName), customQueue).build();
break;
case AMBARI_AGENT:
config = new Builder(orchestrator.ambariClientContainer(customContainerName), customQueue).build();
break;
case AMBARI_DB:
config = new Builder(orchestrator.ambariDbContainer(customContainerName), customQueue).build();
break;
default:
throw new CloudbreakServiceException(String.format("No configuration exist for %s", dc));
}
Component component = new Component(ComponentType.CONTAINER, dc.name(), new Json(config), stack);
return componentConfigProviderService.store(component);
} catch (IllegalArgumentException ignored) {
throw new CloudbreakServiceException(String.format("Failed to parse component ContainerConfig for stack: %d, container: %s", stack.getId(), dc.getName()));
}
}
use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class NetworkV4RequestToNetworkConverter method convert.
public Network convert(NetworkV4Request source) {
Network network = new Network();
network.setName(missingResourceNameGenerator.generateName(APIResourceType.NETWORK));
network.setSubnetCIDR(source.getSubnetCIDR());
network.setOutboundInternetTraffic(OutboundInternetTraffic.ENABLED);
Map<String, Object> parameters = providerParameterCalculator.get(source).asMap();
if (parameters != null) {
try {
network.setAttributes(new Json(parameters));
} catch (IllegalArgumentException ignored) {
throw new BadRequestException("Invalid parameters");
}
}
return network;
}
use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class GatewayTopologyToGatewayTopologyV4RequestConverter method convert.
public GatewayTopologyV4Request convert(GatewayTopology gatewayTopology) {
GatewayTopologyV4Request gatewayTopologyJson = new GatewayTopologyV4Request();
gatewayTopologyJson.setTopologyName(gatewayTopology.getTopologyName());
Json exposedJson = gatewayTopology.getExposedServices();
if (exposedJson != null && StringUtils.isNotEmpty(exposedJson.getValue())) {
try {
gatewayTopologyJson.setExposedServices(exposedJson.get(ExposedServices.class).getServices());
} catch (IOException e) {
LOGGER.info("Failed to add exposedServices to response", e);
throw new CloudbreakApiException("Failed to add exposedServices to response", e);
}
}
return gatewayTopologyJson;
}
use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class GatewayTopologyV4RequestToGatewayTopologyConverter method convertExposedServices.
private void convertExposedServices(GatewayTopology gatewayTopology, GatewayTopologyV4Request source) {
try {
if (!CollectionUtils.isEmpty(source.getExposedServices())) {
ExposedServices exposedServices = gatewayTopologyV4RequestToExposedServicesConverter.convert(source);
gatewayTopology.setExposedServices(new Json(exposedServices));
}
} catch (IllegalArgumentException e) {
throw new BadRequestException("Invalid exposedServices in request. Could not be parsed to JSON.", e);
}
}
use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class InstanceGroupToInstanceGroupV4ResponseConverter method convert.
public InstanceGroupV4Response convert(InstanceGroup source) {
InstanceGroupV4Response instanceGroupResponse = new InstanceGroupV4Response();
instanceGroupResponse.setId(source.getId());
if (source.getTemplate() != null) {
instanceGroupResponse.setTemplate(templateToInstanceTemplateV4ResponseConverter.convert(source.getTemplate()));
}
instanceGroupResponse.setMetadata(source.getNotTerminatedInstanceMetaDataSet().stream().map(s -> instanceMetaDataToInstanceMetaDataV4ResponseConverter.convert(s)).collect(Collectors.toSet()));
if (source.getSecurityGroup() != null) {
instanceGroupResponse.setSecurityGroup(securityGroupToSecurityGroupResponseConverter.convert(source.getSecurityGroup()));
}
Json attributes = source.getAttributes();
if (attributes != null) {
providerParameterCalculator.parse(attributes.getMap(), instanceGroupResponse);
}
instanceGroupResponse.setNodeCount(source.getNodeCount());
instanceGroupResponse.setName(source.getGroupName());
instanceGroupResponse.setMinimumNodeCount(source.getMinimumNodeCount());
instanceGroupResponse.setType(source.getInstanceGroupType());
if (source.getInstanceGroupNetwork() != null) {
instanceGroupResponse.setNetwork(instanceGroupNetworkToInstanceGroupNetworkV4ResponseConverter.convert(source.getInstanceGroupNetwork()));
}
instanceGroupResponse.setAvailabilityZones(source.getAvailabilityZones());
instanceGroupResponse.setScalabilityOption(source.getScalabilityOption() == null ? ScalabilityOption.ALLOWED : source.getScalabilityOption());
return instanceGroupResponse;
}
Aggregations