use of com.sequenceiq.cloudbreak.domain.InstanceGroup 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;
}
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class MetadataSetupService method saveInstanceMetaData.
public int saveInstanceMetaData(Stack stack, Iterable<CloudVmMetaDataStatus> cloudVmMetaDataStatusList, InstanceStatus status) {
int newInstances = 0;
boolean ambariServerFound = false;
Set<InstanceMetaData> allInstanceMetadata = instanceMetaDataRepository.findNotTerminatedForStack(stack.getId());
boolean primaryIgSelected = allInstanceMetadata.stream().anyMatch(imd -> imd.getInstanceMetadataType() == InstanceMetadataType.GATEWAY_PRIMARY);
for (CloudVmMetaDataStatus cloudVmMetaDataStatus : cloudVmMetaDataStatusList) {
CloudInstance cloudInstance = cloudVmMetaDataStatus.getCloudVmInstanceStatus().getCloudInstance();
CloudInstanceMetaData md = cloudVmMetaDataStatus.getMetaData();
long timeInMillis = Calendar.getInstance().getTimeInMillis();
Long privateId = cloudInstance.getTemplate().getPrivateId();
String instanceId = cloudInstance.getInstanceId();
InstanceMetaData instanceMetaDataEntry = createInstanceMetadataIfAbsent(allInstanceMetadata, privateId, instanceId);
if (instanceMetaDataEntry.getInstanceId() == null) {
newInstances++;
}
// CB 1.0.x clusters do not have private id thus we cannot correlate them with instance groups thus keep the original one
InstanceGroup ig = instanceMetaDataEntry.getInstanceGroup();
String group = ig == null ? cloudInstance.getTemplate().getGroupName() : ig.getGroupName();
InstanceGroup instanceGroup = instanceGroupRepository.findOneByGroupNameInStack(stack.getId(), group);
instanceMetaDataEntry.setPrivateIp(md.getPrivateIp());
instanceMetaDataEntry.setPublicIp(md.getPublicIp());
instanceMetaDataEntry.setSshPort(md.getSshPort());
instanceMetaDataEntry.setLocalityIndicator(md.getLocalityIndicator());
instanceMetaDataEntry.setInstanceGroup(instanceGroup);
instanceMetaDataEntry.setInstanceId(instanceId);
instanceMetaDataEntry.setPrivateId(privateId);
instanceMetaDataEntry.setStartDate(timeInMillis);
instanceMetaDataEntry.setSubnetId(cloudInstance.getStringParameter(CloudInstance.SUBNET_ID));
if (instanceMetaDataEntry.getInstanceMetadataType() == null) {
if (ig != null) {
if (InstanceGroupType.GATEWAY.equals(ig.getInstanceGroupType())) {
if (!primaryIgSelected) {
primaryIgSelected = true;
instanceMetaDataEntry.setInstanceMetadataType(InstanceMetadataType.GATEWAY_PRIMARY);
} else {
instanceMetaDataEntry.setInstanceMetadataType(InstanceMetadataType.GATEWAY);
}
} else {
instanceMetaDataEntry.setInstanceMetadataType(InstanceMetadataType.CORE);
}
} else {
instanceMetaDataEntry.setInstanceMetadataType(InstanceMetadataType.CORE);
}
}
if (!ambariServerFound && InstanceGroupType.GATEWAY.equals(instanceGroup.getInstanceGroupType())) {
instanceMetaDataEntry.setAmbariServer(Boolean.TRUE);
ambariServerFound = true;
} else {
instanceMetaDataEntry.setAmbariServer(Boolean.FALSE);
}
if (status != null) {
instanceMetaDataEntry.setInstanceStatus(status);
}
instanceMetaDataRepository.save(instanceMetaDataEntry);
}
return newInstances;
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class StackSyncService method updateMetaDataToTerminated.
private void updateMetaDataToTerminated(Stack stack, InstanceMetaData instanceMetaData) {
InstanceGroup instanceGroup = instanceMetaData.getInstanceGroup();
List<InstanceMetaData> aliveInstancesInInstanceGroup = instanceMetaDataRepository.findAliveInstancesInInstanceGroup(instanceGroup.getId());
instanceGroup.setNodeCount(aliveInstancesInInstanceGroup.size() - 1);
long timeInMillis = Calendar.getInstance().getTimeInMillis();
instanceMetaData.setTerminationDate(timeInMillis);
instanceMetaData.setInstanceStatus(InstanceStatus.TERMINATED);
instanceMetaDataRepository.save(instanceMetaData);
instanceGroupRepository.save(instanceGroup);
String name;
name = instanceMetaData.getDiscoveryFQDN() == null ? instanceMetaData.getInstanceId() : String.format("%s (%s)", instanceMetaData.getInstanceId(), instanceMetaData.getDiscoveryFQDN());
eventService.fireCloudbreakEvent(stack.getId(), AVAILABLE.name(), cloudbreakMessagesService.getMessage(Msg.STACK_SYNC_INSTANCE_DELETED_CBMETADATA.code(), Collections.singletonList(name)));
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class StackSyncService method sync.
private void sync(Stack stack, boolean stackStatusUpdateEnabled) {
Long stackId = stack.getId();
Set<InstanceMetaData> instances = instanceMetaDataRepository.findNotTerminatedForStack(stackId);
Map<InstanceSyncState, Integer> instanceStateCounts = initInstanceStateCounts();
for (InstanceMetaData instance : instances) {
InstanceGroup instanceGroup = instance.getInstanceGroup();
try {
InstanceSyncState state = metadata.getState(stack, instanceGroup, instance.getInstanceId());
syncInstanceStatusByState(stack, instanceStateCounts, instance, state);
} catch (CloudConnectorException e) {
LOGGER.warn(e.getMessage(), e);
eventService.fireCloudbreakEvent(stackId, AVAILABLE.name(), cloudbreakMessagesService.getMessage(Msg.STACK_SYNC_INSTANCE_STATUS_RETRIEVAL_FAILED.code(), Collections.singletonList(instance.getInstanceId())));
instanceStateCounts.put(InstanceSyncState.UNKNOWN, instanceStateCounts.get(InstanceSyncState.UNKNOWN) + 1);
}
}
handleSyncResult(stack, instanceStateCounts, stackStatusUpdateEnabled);
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class TerminationService method terminateInstanceGroups.
private void terminateInstanceGroups(Stack stack) {
for (InstanceGroup instanceGroup : stack.getInstanceGroups()) {
instanceGroup.setSecurityGroup(null);
instanceGroup.setTemplate(null);
instanceGroupRepository.save(instanceGroup);
}
}
Aggregations