use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.
the class InstanceMetadataService method updateInstanceStatus.
public void updateInstanceStatus(Iterable<InstanceGroup> instanceGroup, Map<InstanceGroupType, com.sequenceiq.cloudbreak.api.model.InstanceStatus> newStatusByGroupType) {
for (InstanceGroup group : instanceGroup) {
com.sequenceiq.cloudbreak.api.model.InstanceStatus newStatus = newStatusByGroupType.get(group.getInstanceGroupType());
if (newStatus != null) {
for (InstanceMetaData instanceMetaData : group.getInstanceMetaData()) {
instanceMetaData.setInstanceStatus(newStatus);
instanceMetaDataRepository.save(instanceMetaData);
}
}
}
}
use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.
the class StackService method removeInstance.
public void removeInstance(@Nonnull IdentityUser user, Long stackId, String instanceId) {
requireNonNull(user);
Stack stack = get(stackId);
InstanceMetaData metaData = instanceMetaDataRepository.findByInstanceId(stackId, instanceId);
if (metaData == null) {
throw new NotFoundException(String.format("Metadata for instance %s has not found.", instanceId));
} else {
downscaleValidatorService.checkInstanceIsTheAmbariServerOrNot(metaData.getPublicIp(), metaData.getInstanceMetadataType());
downscaleValidatorService.checkUserHasRightToTerminateInstance(stack.isPublicInAccount(), stack.getOwner(), user.getUserId(), stackId);
flowManager.triggerStackRemoveInstance(stackId, metaData.getInstanceGroupName(), metaData.getDiscoveryFQDN());
}
}
use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.
the class StackService method updateMetaDataStatus.
public InstanceMetaData updateMetaDataStatus(Long id, String hostName, InstanceStatus status) {
InstanceMetaData metaData = instanceMetaDataRepository.findHostInStack(id, hostName);
if (metaData == null) {
throw new NotFoundException(String.format("Metadata not found on stack:'%s' with hostname: '%s'.", id, hostName));
}
metaData.setInstanceStatus(status);
return instanceMetaDataRepository.save(metaData);
}
use of com.sequenceiq.cloudbreak.domain.InstanceMetaData 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.domain.InstanceMetaData in project cloudbreak by hortonworks.
the class ServiceProviderMetadataAdapter method getState.
public InstanceSyncState getState(Stack stack, InstanceGroup instanceGroup, String instanceId) {
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());
InstanceGroup ig = stack.getInstanceGroupByInstanceGroupName(instanceGroup.getGroupName());
CloudInstance instance = null;
for (InstanceMetaData metaData : ig.getAllInstanceMetaData()) {
if (instanceId.equalsIgnoreCase(metaData.getInstanceId())) {
instance = metadataConverter.convert(metaData);
break;
}
}
if (instance != null) {
GetInstancesStateRequest<GetInstancesStateResult> stateRequest = new GetInstancesStateRequest<>(cloudContext, cloudCredential, Collections.singletonList(instance));
LOGGER.info("Triggering event: {}", stateRequest);
eventBus.notify(stateRequest.selector(), eventFactory.createEvent(stateRequest));
try {
GetInstancesStateResult res = stateRequest.await();
LOGGER.info("Result: {}", res);
if (res.isFailed()) {
LOGGER.error("Failed to retrieve instance state", res.getErrorDetails());
throw new OperationException(res.getErrorDetails());
}
return transform(res.getStatuses().get(0).getStatus());
} catch (InterruptedException e) {
LOGGER.error(format("Error while retrieving instance state of: %s", cloudContext), e);
throw new OperationException(e);
}
} else {
return InstanceSyncState.DELETED;
}
}
Aggregations