use of com.sequenceiq.cloudbreak.domain.InstanceMetaData 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.InstanceMetaData 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.InstanceMetaData 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.InstanceMetaData in project cloudbreak by hortonworks.
the class StackSyncService method updateInstances.
public void updateInstances(Stack stack, Iterable<InstanceMetaData> instanceMetaDataList, Collection<CloudVmInstanceStatus> instanceStatuses, boolean stackStatusUpdateEnabled) {
Map<InstanceSyncState, Integer> counts = initInstanceStateCounts();
for (InstanceMetaData metaData : instanceMetaDataList) {
Optional<CloudVmInstanceStatus> status = instanceStatuses.stream().filter(is -> is != null && is.getCloudInstance().getInstanceId() != null && is.getCloudInstance().getInstanceId().equals(metaData.getInstanceId())).findFirst();
InstanceSyncState state = status.isPresent() ? transform(status.get().getStatus()) : InstanceSyncState.DELETED;
syncInstanceStatusByState(stack, counts, metaData, state);
}
handleSyncResult(stack, counts, stackStatusUpdateEnabled);
}
use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.
the class StackResponseHardwareInfoProvider method providerEntriesToStackResponse.
@Override
public StackResponse providerEntriesToStackResponse(Stack stack, StackResponse stackResponse) {
Set<HardwareInfoResponse> hardwareInfoResponses = new HashSet<>();
for (InstanceGroup instanceGroup : stack.getInstanceGroups()) {
for (InstanceMetaData instanceMetaData : instanceGroup.getAllInstanceMetaData()) {
HostMetadata hostMetadata = null;
if (stack.getCluster() != null && instanceMetaData.getDiscoveryFQDN() != null) {
hostMetadata = hostMetadataRepository.findHostInClusterByName(stack.getCluster().getId(), instanceMetaData.getDiscoveryFQDN());
}
HardwareInfoResponse hardwareInfoResponse = new HardwareInfoResponse();
hardwareInfoResponse.setInstanceMetaData(conversionService.convert(instanceMetaData, InstanceMetaDataJson.class));
hardwareInfoResponse.setHostMetadata(conversionService.convert(hostMetadata, HostMetadataResponse.class));
hardwareInfoResponses.add(hardwareInfoResponse);
}
}
stackResponse.setHardwareInfos(hardwareInfoResponses);
return stackResponse;
}
Aggregations