use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.
the class GcpMetadataCollector method groupByPrivateId.
private Map<Long, CloudResource> groupByPrivateId(Iterable<CloudResource> resources) {
Map<Long, CloudResource> privateIdMap = new HashMap<>();
for (CloudResource resource : resources) {
if (ResourceType.GCP_INSTANCE == resource.getType()) {
String resourceName = resource.getName();
Long privateId = GcpStackUtil.getPrivateId(resourceName);
if (privateId != null) {
privateIdMap.put(privateId, resource);
}
}
}
return privateIdMap;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.
the class GcpReservedIpResourceBuilder method build.
@Override
public List<CloudResource> build(GcpContext context, long privateId, AuthenticatedContext auth, Group group, Image image, List<CloudResource> buildableResource, Map<String, String> tags) throws Exception {
List<CloudResource> result = buildableResource;
if (!buildableResource.isEmpty()) {
CloudResource resource = buildableResource.get(0);
String projectId = context.getProjectId();
String region = context.getLocation().getRegion().value();
Address address = new Address();
address.setName(resource.getName());
Map<String, String> customTags = new HashMap<>();
customTags.putAll(tags);
customTags.putAll(defaultCostTaggingService.prepareIpTagging());
address.setLabels(customTags);
Insert networkInsert = context.getCompute().addresses().insert(projectId, region, address);
try {
Operation operation = networkInsert.execute();
if (operation.getHttpErrorStatusCode() != null) {
throw new GcpResourceException(operation.getHttpErrorMessage(), resourceType(), resource.getName());
}
result = Collections.singletonList(createOperationAwareCloudResource(resource, operation));
} catch (GoogleJsonResponseException e) {
throw new GcpResourceException(checkException(e), resourceType(), resource.getName());
}
}
return result;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.
the class OpenStackAttachedDiskResourceBuilder method build.
@Override
public List<CloudResource> build(OpenStackContext context, long privateId, AuthenticatedContext auth, Group group, Image image, List<CloudResource> buildableResource, Map<String, String> tags) throws Exception {
List<CloudResource> resources = new ArrayList<>();
List<CloudResource> syncedResources = Collections.synchronizedList(resources);
Collection<Future<Void>> futures = new ArrayList<>();
for (CloudResource cloudResource : buildableResource) {
Future<Void> submit = intermediateBuilderExecutor.submit(() -> {
CinderVolumeView volumeView = cloudResource.getParameter(VOLUME_VIEW, CinderVolumeView.class);
Volume osVolume = Builders.volume().name(cloudResource.getName()).size(volumeView.getSize()).build();
try {
OSClient<?> osClient = createOSClient(auth);
osVolume = osClient.blockStorage().volumes().create(osVolume);
CloudResource newRes = createPersistedResource(cloudResource, group.getName(), osVolume.getId());
newRes.putParameter(OpenStackConstants.VOLUME_MOUNT_POINT, volumeView.getDevice());
syncedResources.add(newRes);
} catch (OS4JException ex) {
throw new OpenStackResourceException("Volume creation failed", resourceType(), cloudResource.getName(), ex);
}
return null;
});
futures.add(submit);
}
for (Future<Void> future : futures) {
future.get();
}
return resources;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.
the class OpenStackAttachedDiskResourceBuilder method create.
@Override
public List<CloudResource> create(OpenStackContext context, long privateId, AuthenticatedContext auth, Group group, Image image) {
List<CloudResource> cloudResources = new ArrayList<>();
InstanceTemplate template = getInstanceTemplate(group, privateId);
NovaInstanceView instanceView = new NovaInstanceView(context.getName(), template, group.getType(), group.getLoginUserName());
String groupName = group.getName();
String stackName = getUtils().getStackName(auth);
for (int i = 0; i < instanceView.getVolumes().size(); i++) {
String resourceName = resourceNameService.resourceName(resourceType(), stackName, groupName, privateId, i);
CloudResource resource = createNamedResource(resourceType(), groupName, resourceName);
resource.putParameter(VOLUME_VIEW, instanceView.getVolumes().get(i));
cloudResources.add(resource);
}
return cloudResources;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.
the class OpenStackFloatingIPBuilder method build.
@Override
public List<CloudResource> build(OpenStackContext context, long privateId, AuthenticatedContext auth, Group group, Image image, List<CloudResource> buildableResource, Map<String, String> tags) {
CloudResource resource = buildableResource.get(0);
try {
String publicNetId = context.getStringParameter(OpenStackConstants.PUBLIC_NET_ID);
if (publicNetId != null) {
OSClient<?> osClient = createOSClient(auth);
List<CloudResource> computeResources = context.getComputeResources(privateId);
CloudResource instance = getInstance(computeResources);
FloatingIP unusedIp = osClient.compute().floatingIps().allocateIP(publicNetId);
ActionResponse response = osClient.compute().floatingIps().addFloatingIP(instance.getParameter(OpenStackConstants.SERVER, Server.class), unusedIp.getFloatingIpAddress());
if (!response.isSuccess()) {
throw new OpenStackResourceException("Add floating-ip to server failed", resourceType(), resource.getName(), auth.getCloudContext().getId(), response.getFault());
}
return Collections.singletonList(createPersistedResource(resource, group.getName(), unusedIp.getId()));
}
return Collections.emptyList();
} catch (OS4JException ex) {
throw new OpenStackResourceException("Add floating-ip to server failed", resourceType(), resource.getName(), ex);
}
}
Aggregations