use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.
the class MetadataSetupService method saveInstanceMetaData.
public int saveInstanceMetaData(Stack stack, Iterable<CloudVmMetaDataStatus> cloudVmMetaDataStatusList, InstanceStatus status) {
int newInstances = 0;
Set<InstanceMetaData> allInstanceMetadata = instanceMetaDataService.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 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 = instanceGroupService.findOneByGroupNameInStack(stack.getId(), group).orElse(null);
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(clock.getCurrentTimeMillis());
instanceMetaDataEntry.setSubnetId(cloudInstance.getSubnetId());
instanceMetaDataEntry.setAvailabilityZone(cloudInstance.getAvailabilityZone());
instanceMetaDataEntry.setInstanceName(cloudInstance.getStringParameter(CloudInstance.INSTANCE_NAME));
instanceMetaDataEntry.setLifeCycle(convertLifeCycle(md));
if (instanceMetaDataEntry.getInstanceMetadataType() == null) {
if (ig != null) {
if (!primaryIgSelected && ig.getInstanceGroupType() == com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupType.MASTER) {
primaryIgSelected = true;
instanceMetaDataEntry.setInstanceMetadataType(InstanceMetadataType.GATEWAY_PRIMARY);
} else {
instanceMetaDataEntry.setInstanceMetadataType(InstanceMetadataType.GATEWAY);
}
} else {
instanceMetaDataEntry.setInstanceMetadataType(InstanceMetadataType.GATEWAY);
}
}
if (status != null) {
instanceMetaDataEntry.setInstanceStatus(status);
}
instanceMetaDataService.save(instanceMetaDataEntry);
}
return newInstances;
}
use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.
the class FreeIpaStackHealthDetailsService method getHealthDetails.
public HealthDetailsFreeIpaResponse getHealthDetails(String environmentCrn, String accountId) {
Stack stack = stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(environmentCrn, accountId);
List<InstanceMetaData> instances = stack.getAllInstanceMetaDataList();
HealthDetailsFreeIpaResponse response = new HealthDetailsFreeIpaResponse();
for (InstanceMetaData instance : instances) {
if (shouldRunHealthCheck(instance)) {
try {
NodeHealthDetails nodeHealthDetails = freeIpaInstanceHealthDetailsService.getInstanceHealthDetails(stack, instance);
response.addNodeHealthDetailsFreeIpaResponses(nodeHealthDetails);
} catch (Exception e) {
addUnreachableResponse(instance, response, e.getLocalizedMessage());
LOGGER.error(String.format("Unable to check the health of FreeIPA instance: %s", instance.getInstanceId()), e);
}
} else {
NodeHealthDetails nodeResponse = new NodeHealthDetails();
response.addNodeHealthDetailsFreeIpaResponses(nodeResponse);
nodeResponse.setName(instance.getDiscoveryFQDN());
nodeResponse.setStatus(instance.getInstanceStatus());
nodeResponse.setInstanceId(instance.getInstanceId());
nodeResponse.addIssue("Unable to check health as instance is " + instance.getInstanceStatus().name());
}
}
return updateResponse(stack, response);
}
use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.
the class HostMetadataSetup method updateWithHostData.
private void updateWithHostData(Stack stack, Collection<InstanceMetaData> metadataToUpdate) throws CloudbreakOrchestratorException {
List<String> privateIps = metadataToUpdate.stream().map(InstanceMetaData::getPrivateIp).collect(Collectors.toList());
GatewayConfig gatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
Map<String, String> members = hostOrchestrator.getMembers(gatewayConfig, privateIps);
LOGGER.debug("Received host names from hosts: {}, original targets: {}", members.values(), privateIps);
for (InstanceMetaData instanceMetaData : metadataToUpdate) {
String address = members.get(instanceMetaData.getPrivateIp());
instanceMetaData.setDiscoveryFQDN(address);
LOGGER.debug("Domain used for instance: {} original: {}, fqdn: {}", instanceMetaData.getInstanceId(), address, instanceMetaData.getDiscoveryFQDN());
}
}
use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.
the class RepairInstancesService method rebootInstances.
/**
* If no instance passed in request, reboot all bad instances
* If instances passed in request, reboot all valid passed bad instances
* If force and instances passed in request, reboot all valid passed instances
* If force and no instances passed in request, reboot all instances
*
* @param accountId - The account id for the instance to reboot.
* @param request - A RebootInstanceRequest containing request parameters.
*/
public OperationStatus rebootInstances(String accountId, RebootInstancesRequest request) {
Stack stack = stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(request.getEnvironmentCrn(), accountId);
Map<String, InstanceMetaData> allInstancesByInstanceId = getAllInstancesFromStack(stack);
Map<String, InstanceStatus> healthMap = request.isForceReboot() ? Collections.emptyMap() : getInstanceHealthMap(accountId, request.getEnvironmentCrn());
Map<String, InstanceMetaData> instancesToReboot = getInstancesToRepair(healthMap, allInstancesByInstanceId, request.getInstanceIds(), request.isForceReboot(), true);
if (instancesToReboot.keySet().isEmpty()) {
throw new NotFoundException("No unhealthy instances to reboot. Maybe use the force option.");
}
Operation operation = operationService.startOperation(accountId, OperationType.REBOOT, Set.of(stack.getEnvironmentCrn()), Collections.emptySet());
if (operation.getStatus() == OperationState.RUNNING) {
stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.REPAIR_REQUESTED, "Reboot requested");
flowManager.notify(REBOOT_EVENT.event(), new RebootInstanceEvent(REBOOT_EVENT.event(), stack.getId(), instancesToReboot.keySet().stream().collect(Collectors.toList()), operation.getOperationId()));
}
return operationToOperationStatusConverter.convert(operation);
}
use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.
the class ProviderChecker method updateAndGetStatuses.
public List<ProviderSyncResult> updateAndGetStatuses(Stack stack, Set<InstanceMetaData> checkableInstances, Map<InstanceMetaData, DetailedStackStatus> instanceHealthStatusMap, boolean updateStatusFromFlow) {
return checkedMeasure(() -> {
List<ProviderSyncResult> results = new ArrayList<>();
List<CloudVmInstanceStatus> statuses = stackInstanceProviderChecker.checkStatus(stack, checkableInstances);
if (!updateStatusFromFlow && flowLogService.isOtherFlowRunning(stack.getId())) {
throw new InterruptSyncingException(":::Auto sync::: interrupt syncing in updateAndGetStatuses, flow is running on freeipa stack " + stack.getName());
} else {
statuses.forEach(s -> {
Optional<InstanceMetaData> instanceMetaData = checkableInstances.stream().filter(i -> s.getCloudInstance().getInstanceId().equals(i.getInstanceId())).findFirst();
if (instanceMetaData.isPresent()) {
InstanceStatus instanceStatus = updateStatuses(s, instanceMetaData.get(), instanceHealthStatusMap);
if (instanceStatus != null) {
results.add(new ProviderSyncResult("", instanceStatus, false, s.getCloudInstance().getInstanceId()));
}
} else {
LOGGER.info(":::Auto sync::: Cannot find instanceMetaData");
}
});
checkableInstances.forEach(instanceMetaData -> {
if (statuses.stream().noneMatch(s -> s.getCloudInstance().getInstanceId().equals(instanceMetaData.getInstanceId()))) {
if (updateStatus) {
setStatusIfNotTheSame(instanceMetaData, InstanceStatus.DELETED_ON_PROVIDER_SIDE);
instanceMetaDataService.save(instanceMetaData);
} else {
LOGGER.debug("updateStatus flag is false, don't update status");
}
}
});
return results;
}
}, LOGGER, ":::Auto sync::: provider is checked in {}ms");
}
Aggregations