use of com.sequenceiq.common.api.type.ResourceType in project cloudbreak by hortonworks.
the class AzureVolumeResourceBuilder method checkResources.
@Override
protected List<CloudResourceStatus> checkResources(ResourceType type, AzureContext context, AuthenticatedContext auth, Iterable<CloudResource> resources) {
AzureClient client = getAzureClient(auth);
List<CloudResource> volumeResources = StreamSupport.stream(resources.spliterator(), false).filter(r -> r.getType().equals(resourceType())).collect(toList());
CloudResource resourceGroup = context.getNetworkResources().stream().filter(r -> r.getType().equals(ResourceType.AZURE_RESOURCE_GROUP)).findFirst().orElseThrow(() -> new AzureResourceException("Resource group resource not found"));
String resourceGroupName = resourceGroup.getName();
PagedList<Disk> existingDisks = client.listDisksByResourceGroup(resourceGroupName);
ResourceStatus volumeSetStatus = getResourceStatus(existingDisks, volumeResources);
return volumeResources.stream().map(resource -> new CloudResourceStatus(resource, volumeSetStatus)).collect(toList());
}
use of com.sequenceiq.common.api.type.ResourceType in project cloudbreak by hortonworks.
the class YarnResourceConnector method check.
@Override
public List<CloudResourceStatus> check(AuthenticatedContext authenticatedContext, List<CloudResource> resources) {
YarnClient yarnClient = yarnClientUtil.createYarnClient(authenticatedContext);
List<CloudResourceStatus> result = new ArrayList<>();
for (CloudResource resource : resources) {
ResourceType resourceType = resource.getType();
if (resourceType == YARN_APPLICATION || resourceType == YARN_LOAD_BALANCER) {
LOGGER.debug("Checking Yarn application status of: {}", resource.getName());
try {
ApplicationDetailRequest applicationDetailRequest = new ApplicationDetailRequest();
applicationDetailRequest.setName(resource.getName());
ResponseContext responseContext = yarnClient.getApplicationDetail(applicationDetailRequest);
if (responseContext.getStatusCode() == YarnResourceConstants.HTTP_SUCCESS) {
ApplicationDetailResponse applicationDetailResponse = (ApplicationDetailResponse) responseContext.getResponseObject();
result.add(new CloudResourceStatus(resource, YarnApplicationStatus.mapResourceStatus(applicationDetailResponse.getState())));
} else if (responseContext.getStatusCode() == YarnResourceConstants.HTTP_NOT_FOUND) {
result.add(new CloudResourceStatus(resource, ResourceStatus.DELETED, "Yarn application has been killed."));
} else if (responseContext.getResponseError() != null) {
throw new CloudConnectorException(String.format("Yarn Application status check failed: HttpStatusCode: %d, Error: %s", responseContext.getStatusCode(), responseContext.getResponseError().getDiagnostics()));
} else {
throw new CloudConnectorException(String.format("Yarn Application status check failed: Invalid HttpStatusCode: %d", responseContext.getStatusCode()));
}
} catch (MalformedURLException | RuntimeException e) {
throw new CloudConnectorException(String.format("Invalid resource exception: %s", e.getMessage()), e);
}
} else {
throw new CloudConnectorException(String.format("Invalid resource type: %s", resource.getType()));
}
}
return result;
}
use of com.sequenceiq.common.api.type.ResourceType in project cloudbreak by hortonworks.
the class YarnResourceConnector method terminate.
@Override
public List<CloudResourceStatus> terminate(AuthenticatedContext authenticatedContext, CloudStack stack, List<CloudResource> cloudResources) {
for (CloudResource resource : cloudResources) {
ResourceType resourceType = resource.getType();
if (resourceType == YARN_APPLICATION || resourceType == YARN_LOAD_BALANCER) {
YarnClient yarnClient = yarnClientUtil.createYarnClient(authenticatedContext);
String yarnApplicationName = resource.getName();
String stackName = authenticatedContext.getCloudContext().getName();
LOGGER.debug("Terminate stack: {}", stackName);
try {
DeleteApplicationRequest deleteApplicationRequest = new DeleteApplicationRequest();
deleteApplicationRequest.setName(yarnApplicationName);
yarnClient.deleteApplication(deleteApplicationRequest);
LOGGER.info("Yarn Application has been deleted");
} catch (MalformedURLException | YarnClientException e) {
throw new CloudConnectorException("Stack cannot be deleted", e);
}
} else {
throw new CloudConnectorException(String.format("Invalid resource type: %s", resource.getType()));
}
}
return check(authenticatedContext, cloudResources);
}
use of com.sequenceiq.common.api.type.ResourceType in project cloudbreak by hortonworks.
the class CloudFailureHandler method doRollback.
private void doRollback(AuthenticatedContext auth, List<CloudResourceStatus> statuses, Collection<Long> rollbackIds, Group group, ResourceBuilderContext ctx, ResourceBuilders resourceBuilders, Boolean upscale) {
Variant variant = auth.getCloudContext().getVariant();
LOGGER.info("Rollback resources for the following private ids: {}", rollbackIds);
if (getRemovableInstanceTemplates(group, rollbackIds).size() <= 0 && !upscale) {
LOGGER.info("InstanceGroup node count lower than 1 which is incorrect so error will be thrown");
throwError(statuses);
} else {
Map<ResourceType, ComputeResourceBuilder<ResourceBuilderContext>> resourceBuilderMap = getResourceBuilderMap(resourceBuilders, variant);
for (CloudResourceStatus cloudResourceStatus : statuses) {
try {
if (rollbackIds.contains(cloudResourceStatus.getPrivateId())) {
ComputeResourceBuilder<ResourceBuilderContext> resourceBuilderForType = resourceBuilderMap.get(cloudResourceStatus.getCloudResource().getType());
deleteResource(auth, ctx, resourceBuilderForType, cloudResourceStatus);
}
} catch (Exception e) {
LOGGER.warn("Resource can not be deleted. Reason: " + e.getMessage(), e);
}
}
}
}
use of com.sequenceiq.common.api.type.ResourceType in project cloudbreak by hortonworks.
the class AwsRdsLaunchServiceTest method checkOutputResourceInternal.
private void checkOutputResourceInternal(List<CloudResourceStatus> cloudResourceStatuses, ResourceType type, String nameExpected, boolean existenceExpected) {
Optional<CloudResourceStatus> cloudResourceStatusOptional = cloudResourceStatuses.stream().filter(resource -> resource.getCloudResource().getType() == type).findFirst();
if (existenceExpected) {
assertThat(cloudResourceStatusOptional.isPresent()).isTrue();
CloudResourceStatus cloudResourceStatus = cloudResourceStatusOptional.get();
assertThat(cloudResourceStatus.getStatus()).isEqualTo(ResourceStatus.CREATED);
assertThat(cloudResourceStatus.getCloudResource().getName()).isEqualTo(nameExpected);
} else {
assertThat(cloudResourceStatusOptional.isEmpty()).isTrue();
}
}
Aggregations