use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.
the class NetworkResourceService method buildResources.
public List<CloudResourceStatus> buildResources(ResourceBuilderContext context, AuthenticatedContext auth, Network network, Security security) throws Exception {
CloudContext cloudContext = auth.getCloudContext();
List<CloudResourceStatus> results = new ArrayList<>();
for (NetworkResourceBuilder builder : resourceBuilders.network(cloudContext.getPlatform())) {
PollGroup pollGroup = InMemoryStateStore.getStack(auth.getCloudContext().getId());
if (pollGroup != null && CANCELLED.equals(pollGroup)) {
break;
}
try {
CloudResource buildableResource = builder.create(context, auth, network);
createResource(auth, buildableResource);
CloudResource resource = builder.build(context, auth, network, security, buildableResource);
updateResource(auth, resource);
PollTask<List<CloudResourceStatus>> task = statusCheckFactory.newPollResourceTask(builder, auth, Collections.singletonList(resource), context, true);
List<CloudResourceStatus> pollerResult = syncPollingScheduler.schedule(task);
results.addAll(pollerResult);
} catch (ResourceNotNeededException e) {
LOGGER.warn("Skipping resource creation: {}", e.getMessage());
}
}
return results;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.
the class YarnMetadataCollector method collect.
@Override
public List<CloudVmMetaDataStatus> collect(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms) {
try {
YarnClient yarnClient = yarnClientUtil.createYarnClient(authenticatedContext);
CloudResource yarnApplication = getYarnApplcationResource(resources);
ApplicationDetailRequest applicationDetailRequest = new ApplicationDetailRequest();
applicationDetailRequest.setName(yarnApplication.getName());
ResponseContext responseContext = yarnClient.getApplicationDetail(applicationDetailRequest);
if (responseContext.getStatusCode() == YarnResourceConstants.HTTP_SUCCESS) {
ApplicationDetailResponse applicationDetailResponse = (ApplicationDetailResponse) responseContext.getResponseObject();
ListMultimap<String, CloudInstance> groupInstancesByInstanceGroup = groupInstancesByInstanceGroup(vms);
ListMultimap<String, Container> groupContainersByInstanceGroup = groupContainersByInstanceGroup(applicationDetailResponse.getContainers());
List<CloudVmMetaDataStatus> cloudVmMetaDataStatuses = Lists.newArrayList();
for (String groupName : groupContainersByInstanceGroup.keySet()) {
List<CloudInstance> groupInstances = groupInstancesByInstanceGroup.get(groupName);
List<Container> groupContainers = groupContainersByInstanceGroup.get(groupName);
Map<String, CloudInstance> mapByInstanceId = mapByInstanceId(groupInstances);
Queue<CloudInstance> untrackedInstances = untrackedInstances(groupInstances);
for (Container container : groupContainers) {
String containerId = container.getId();
CloudInstance cloudInstance = mapByInstanceId.get(containerId);
if (cloudInstance == null) {
if (!untrackedInstances.isEmpty()) {
cloudInstance = untrackedInstances.remove();
cloudInstance = new CloudInstance(containerId, cloudInstance.getTemplate(), cloudInstance.getAuthentication());
}
}
if (cloudInstance != null) {
String ipAddress = container.getIp();
CloudInstanceMetaData md = new CloudInstanceMetaData(ipAddress, ipAddress);
CloudVmInstanceStatus cloudVmInstanceStatus = new CloudVmInstanceStatus(cloudInstance, InstanceStatus.CREATED);
CloudVmMetaDataStatus cloudVmMetaDataStatus = new CloudVmMetaDataStatus(cloudVmInstanceStatus, md);
cloudVmMetaDataStatuses.add(cloudVmMetaDataStatus);
}
}
}
return cloudVmMetaDataStatuses;
} else {
ApplicationErrorResponse errorResponse = responseContext.getResponseError();
throw new CloudConnectorException(String.format("Failed to get yarn application details: HTTP Return: %d Error: %s", responseContext.getStatusCode(), errorResponse == null ? "unknown" : errorResponse.getDiagnostics()));
}
} catch (MalformedURLException ex) {
throw new CloudConnectorException("Failed to get yarn application details", ex);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.
the class ServiceProviderConnectorAdapter method removeInstances.
public Set<String> removeInstances(Stack stack, Set<String> instanceIds, String instanceGroup) {
LOGGER.debug("Assembling downscale stack event for stack: {}", stack);
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
List<CloudResource> resources = cloudResourceConverter.convert(stack.getResources());
List<CloudInstance> instances = new ArrayList<>();
InstanceGroup group = stack.getInstanceGroupByInstanceGroupName(instanceGroup);
for (InstanceMetaData metaData : group.getAllInstanceMetaData()) {
if (instanceIds.contains(metaData.getInstanceId())) {
CloudInstance cloudInstance = metadataConverter.convert(metaData);
instances.add(cloudInstance);
}
}
CloudStack cloudStack = cloudStackConverter.convertForDownscale(stack, instanceIds);
DownscaleStackRequest downscaleRequest = new DownscaleStackRequest(cloudContext, cloudCredential, cloudStack, resources, instances);
LOGGER.info("Triggering downscale stack event: {}", downscaleRequest);
eventBus.notify(downscaleRequest.selector(), eventFactory.createEvent(downscaleRequest));
try {
DownscaleStackResult res = downscaleRequest.await();
LOGGER.info("Downscale stack result: {}", res);
if (res.getStatus().equals(EventStatus.FAILED)) {
LOGGER.error("Failed to downscale the stack", res.getErrorDetails());
throw new OperationException(res.getErrorDetails());
}
return instanceIds;
} catch (InterruptedException e) {
LOGGER.error("Error while downscaling the stack", e);
throw new OperationException(e);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.
the class CloudResourcePersisterService method persist.
@Override
public ResourceNotification persist(ResourceNotification notification) {
LOGGER.debug("Resource allocation notification received: {}", notification);
Long stackId = notification.getCloudContext().getId();
CloudResource cloudResource = notification.getCloudResource();
Resource resource = getConversionService().convert(cloudResource, Resource.class);
ResourceRepository resourceRepository = getResourceRepository();
Resource persistedResource = resourceRepository.findByStackIdAndNameAndType(stackId, cloudResource.getName(), cloudResource.getType());
if (persistedResource != null) {
LOGGER.warn("Trying to persist a resource (name: {}, type: {}, stackId: {}) that is already persisted, skipping..", cloudResource.getName(), cloudResource.getType().name(), stackId);
return notification;
}
resource.setStack(getStackRepository().findOne(stackId));
resourceRepository.save(resource);
return notification;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.
the class CloudResourcePersisterService method update.
@Override
public ResourceNotification update(ResourceNotification notification) {
LOGGER.debug("Resource update notification received: {}", notification);
Long stackId = notification.getCloudContext().getId();
CloudResource cloudResource = notification.getCloudResource();
ResourceRepository repository = getResourceRepository();
Resource persistedResource = repository.findByStackIdAndNameAndType(stackId, cloudResource.getName(), cloudResource.getType());
Resource resource = getConversionService().convert(cloudResource, Resource.class);
updateWithPersistedFields(resource, persistedResource);
resource.setStack(getStackRepository().findOne(stackId));
repository.save(resource);
return notification;
}
Aggregations