use of com.sequenceiq.common.api.type.ResourceType in project cloudbreak by hortonworks.
the class AwsEfsResourceBuilder method checkResources.
@Override
protected List<CloudResourceStatus> checkResources(ResourceType type, AwsContext context, AuthenticatedContext auth, Iterable<CloudResource> resources) {
AmazonEfsClient client = getAmazonEfsClient(auth);
List<CloudResource> efsResources = StreamSupport.stream(resources.spliterator(), false).filter(r -> r.getType().equals(resourceType())).collect(Collectors.toList());
List<String> efsIds = new ArrayList<>();
List<CloudResourceStatus> cloudResourceStatusList = new ArrayList<>();
for (CloudResource efsResource : efsResources) {
CloudEfsAttributes efsAttributes = efsResource.getParameter(CloudResource.ATTRIBUTES, CloudEfsAttributes.class);
String efsId = efsAttributes.getFileSystemId();
efsIds.add(efsId);
DescribeFileSystemsRequest request = new DescribeFileSystemsRequest().withFileSystemId(efsId);
DescribeFileSystemsResult result = client.describeFileSystems(request);
List<CloudResourceStatus> efsStatusList = getResourceStatus(efsResource, efsId, result);
cloudResourceStatusList.addAll(efsStatusList);
}
LOGGER.debug("got EFS status for [{}]", String.join(",", efsIds));
return cloudResourceStatusList;
}
use of com.sequenceiq.common.api.type.ResourceType in project cloudbreak by hortonworks.
the class AwsVolumeResourceBuilder method checkResources.
@Override
protected List<CloudResourceStatus> checkResources(ResourceType type, AwsContext context, AuthenticatedContext auth, Iterable<CloudResource> resources) {
AmazonEc2Client client = getAmazonEC2Client(auth);
Pair<List<String>, List<CloudResource>> volumes = volumeResourceCollector.getVolumeIdsByVolumeResources(resources, resourceType(), volumeSetAttributes());
DescribeVolumesRequest describeVolumesRequest = new DescribeVolumesRequest(volumes.getFirst());
LOGGER.debug("Going to describe volume(s) with id(s): [{}]", String.join(",", describeVolumesRequest.getVolumeIds()));
AtomicReference<ResourceStatus> volumeSetStatus = new AtomicReference<>();
try {
DescribeVolumesResult result = client.describeVolumes(describeVolumesRequest);
volumeSetStatus.set(getResourceStatus(result));
} catch (AmazonEC2Exception e) {
if (!"InvalidVolume.NotFound".equals(e.getErrorCode())) {
throw e;
}
LOGGER.info("The volume doesn't need to be deleted as it does not exist on the provider side. Reason: {}", e.getMessage());
volumeSetStatus.set(DELETED);
}
LOGGER.debug("[{}] volume set status is {}", String.join(",", volumes.getFirst()), volumeSetStatus);
return volumes.getSecond().stream().map(resource -> new CloudResourceStatus(resource, volumeSetStatus.get())).collect(Collectors.toList());
}
use of com.sequenceiq.common.api.type.ResourceType in project cloudbreak by hortonworks.
the class AzureResourceConnector method check.
@Override
public List<CloudResourceStatus> check(AuthenticatedContext authenticatedContext, List<CloudResource> resources) {
List<CloudResourceStatus> result = new ArrayList<>();
AzureClient client = authenticatedContext.getParameter(AzureClient.class);
String stackName = azureUtils.getStackName(authenticatedContext.getCloudContext());
for (CloudResource resource : resources) {
ResourceType resourceType = resource.getType();
if (resourceType == ResourceType.ARM_TEMPLATE) {
LOGGER.debug("Checking Azure stack status of: {}", stackName);
checkTemplateDeployment(result, client, stackName, resource);
} else {
if (!resourceType.name().startsWith("AZURE")) {
throw new CloudConnectorException(String.format("Invalid resource type: %s", resourceType));
}
}
}
return result;
}
use of com.sequenceiq.common.api.type.ResourceType in project cloudbreak by hortonworks.
the class GcpAttachedDiskResourceBuilder method build.
@Override
public List<CloudResource> build(GcpContext context, CloudInstance instance, long privateId, AuthenticatedContext auth, Group group, List<CloudResource> resources, CloudStack cloudStack) throws Exception {
InstanceTemplate template = group.getReferenceInstanceTemplate();
List<String> operations = new ArrayList<>();
List<String> syncedOperations = Collections.synchronizedList(operations);
String projectId = context.getProjectId();
Compute compute = context.getCompute();
Collection<Future<Void>> futures = new ArrayList<>();
List<CloudResource> buildableResource = resources.stream().filter(cloudResource -> CommonStatus.REQUESTED.equals(cloudResource.getStatus())).collect(Collectors.toList());
List<CloudResource> result = new ArrayList<>();
for (CloudResource volumeSetResource : buildableResource) {
VolumeSetAttributes volumeSetAttributes = volumeSetResource.getParameter(CloudResource.ATTRIBUTES, VolumeSetAttributes.class);
for (VolumeSetAttributes.Volume volume : volumeSetAttributes.getVolumes()) {
Map<String, String> labels = gcpLabelUtil.createLabelsFromTags(cloudStack);
Disk disk = createDisk(projectId, volume, labels, volumeSetAttributes);
customGcpDiskEncryptionService.addEncryptionKeyToDisk(template, disk);
Future<Void> submit = intermediateBuilderExecutor.submit(() -> {
Insert insDisk = compute.disks().insert(projectId, volumeSetAttributes.getAvailabilityZone(), disk);
try {
Operation operation = insDisk.execute();
syncedOperations.add(operation.getName());
if (operation.getHttpErrorStatusCode() != null) {
throw new GcpResourceException(operation.getHttpErrorMessage(), resourceType(), disk.getName());
}
} catch (TokenResponseException e) {
throw gcpStackUtil.getMissingServiceAccountKeyError(e, projectId);
} catch (GoogleJsonResponseException e) {
throw new GcpResourceException(checkException(e), resourceType(), disk.getName());
}
return null;
});
futures.add(submit);
}
volumeSetResource.putParameter(OPERATION_ID, operations);
result.add(new Builder().cloudResource(volumeSetResource).status(CommonStatus.CREATED).params(volumeSetResource.getParameters()).build());
}
for (Future<Void> future : futures) {
future.get();
}
result.addAll(resources.stream().filter(cloudResource -> CommonStatus.CREATED.equals(cloudResource.getStatus())).collect(Collectors.toList()));
return result;
}
use of com.sequenceiq.common.api.type.ResourceType in project cloudbreak by hortonworks.
the class GcpAttachedDiskResourceBuilder method checkResources.
@Override
public List<CloudResourceStatus> checkResources(GcpContext context, AuthenticatedContext auth, List<CloudResource> resources) {
List<CloudResourceStatus> result = new ArrayList<>();
for (CloudResource resource : resources) {
LOGGER.debug("Check {} resource: {}", resourceType(), resource);
List<String> operationIds = Optional.ofNullable(resource.getParameter(OPERATION_ID, List.class)).orElse(List.of());
boolean finished = operationIds.isEmpty() || operationIds.stream().allMatch(operationId -> {
try {
Operation operation = getResourceChecker().check(context, operationId, resources);
return operation == null || gcpStackUtil.isOperationFinished(operation);
} catch (Exception e) {
CloudContext cloudContext = auth.getCloudContext();
throw new GcpResourceException("Error during status check", resourceType(), cloudContext.getName(), cloudContext.getId(), resource.getName(), e);
}
});
ResourceStatus successStatus = context.isBuild() ? ResourceStatus.CREATED : ResourceStatus.DELETED;
result.add(new CloudResourceStatus(resource, finished ? successStatus : ResourceStatus.IN_PROGRESS));
if (finished) {
if (successStatus == ResourceStatus.CREATED) {
LOGGER.debug("Creation of {} was successful", resource);
} else {
LOGGER.debug("Deletion of {} was successful", resource);
}
}
}
return result;
}
Aggregations