use of com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException in project cloudbreak by hortonworks.
the class HostMetadataSetup method updateWithHostData.
private void updateWithHostData(Stack stack, Collection<InstanceMetaData> metadataToUpdate) {
try {
LOGGER.info("Update metadatas: {}", metadataToUpdate);
List<String> privateIps = metadataToUpdate.stream().filter(instanceMetaData -> InstanceStatus.CREATED.equals(instanceMetaData.getInstanceStatus())).map(InstanceMetaData::getPrivateIp).collect(Collectors.toList());
if (!privateIps.isEmpty()) {
GatewayConfig gatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
Map<String, String> members = hostOrchestrator.getMembers(gatewayConfig, privateIps);
LOGGER.info("Received host names from hosts: {}, original targets: {}", members.values(), privateIps);
for (InstanceMetaData instanceMetaData : metadataToUpdate) {
String privateIp = instanceMetaData.getPrivateIp();
String fqdnFromTheCluster = members.get(privateIp);
String discoveryFQDN = instanceMetaData.getDiscoveryFQDN();
if (Strings.isNullOrEmpty(discoveryFQDN) || !discoveryFQDN.equals(fqdnFromTheCluster)) {
instanceMetaData.setDiscoveryFQDN(fqdnFromTheCluster);
LOGGER.info("Discovery FQDN has been updated for instance: {} original: {}, fqdn: {}", instanceMetaData.getInstanceId(), fqdnFromTheCluster, discoveryFQDN);
} else {
LOGGER.debug("There is no need to update the FQDN for node, private ip: '{}' with FQDN: '{}'", privateIp, discoveryFQDN);
}
}
} else {
LOGGER.info("There is no hosts to update");
}
} catch (Exception e) {
throw new CloudbreakRuntimeException(e);
}
}
use of com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException in project cloudbreak by hortonworks.
the class HostMetadataSetup method setupNewHostMetadata.
public void setupNewHostMetadata(Long stackId, Collection<String> newAddresses) {
try {
transactionService.required(() -> {
LOGGER.info("Extending host metadata: {}", newAddresses);
Stack stack = stackService.getByIdWithListsInTransaction(stackId);
Set<InstanceMetaData> newInstanceMetadata = instanceMetaDataService.getNotDeletedAndNotZombieInstanceMetadataByStackId(stackId).stream().filter(instanceMetaData -> newAddresses.contains(instanceMetaData.getPrivateIp())).collect(Collectors.toSet());
updateWithHostData(stack, newInstanceMetadata);
instanceMetaDataService.saveAll(newInstanceMetadata);
});
} catch (TransactionExecutionException e) {
throw new CloudbreakRuntimeException(e.getCause());
}
}
use of com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException in project cloudbreak by hortonworks.
the class MeteringAzureMetadataPatchService method isAffected.
@Override
public boolean isAffected(Stack stack) {
try {
boolean affected = false;
if (StackType.WORKLOAD.equals(stack.getType()) && CloudPlatform.AZURE.equalsIgnoreCase(stack.getCloudPlatform())) {
try {
final Long dateBeforeTimestamp = dateStringToTimestampForImage(meteringAzureMetadataPatchConfig.getDateBefore());
Optional<StatedImage> statedImageOpt = stackImageService.getStatedImageInternal(stack);
if (statedImageOpt.isEmpty() || statedImageOpt.get().getImage() == null || statedImageOpt.get().getImage().getCreated() < dateBeforeTimestamp) {
affected = true;
}
} catch (Exception e) {
String errorMessage = String.format("Cannot determine stack with crn %s is affected by azure metadata issue", stack.getResourceCrn());
LOGGER.debug(errorMessage, e);
throw new ExistingStackPatchApplyException(errorMessage, e);
}
}
return affected;
} catch (Exception e) {
LOGGER.warn("Error during obtaining image / catalog for stack " + stack.getResourceCrn(), e);
throw new CloudbreakRuntimeException("Error during obtaining image / catalog for stack " + stack.getResourceCrn(), e);
}
}
use of com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException in project cloudbreak by hortonworks.
the class StackDownscaleService method startStackDownscale.
public void startStackDownscale(StackScalingFlowContext context, StackDownscaleTriggerEvent stackDownscaleTriggerEvent) {
LOGGER.debug("Downscaling of stack {}", context.getStack().getId());
stackUpdater.updateStackStatus(context.getStack().getId(), DetailedStackStatus.DOWNSCALE_IN_PROGRESS);
Set<Long> privateIds = null;
if (stackDownscaleTriggerEvent.getHostGroupsWithPrivateIds() != null) {
privateIds = stackDownscaleTriggerEvent.getHostGroupsWithPrivateIds().values().stream().flatMap(Collection::stream).collect(Collectors.toSet());
}
String msgParam;
if (CollectionUtils.isNotEmpty(privateIds)) {
Stack stack = stackService.getByIdWithListsInTransaction(context.getStack().getId());
List<String> instanceIdList = stackService.getInstanceIdsForPrivateIds(stack.getInstanceMetaDataAsList(), privateIds);
msgParam = String.join(",", instanceIdList);
} else if (stackDownscaleTriggerEvent.getHostGroupsWithAdjustment() != null) {
Integer adjustmentSize = stackDownscaleTriggerEvent.getHostGroupsWithAdjustment().values().stream().reduce(0, Integer::sum);
msgParam = String.valueOf(adjustmentSize);
} else {
throw new CloudbreakRuntimeException("No adjustment was defined");
}
flowMessageService.fireEventAndLog(context.getStack().getId(), UPDATE_IN_PROGRESS.name(), STACK_DOWNSCALE_INSTANCES, msgParam);
}
use of com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException in project cloudbreak by hortonworks.
the class UnboundRestartPatchService method isAffected.
@Override
public boolean isAffected(Stack stack) {
try {
boolean affected = false;
if (AFFECTED_STACK_VERSION.equals(stack.getStackVersion())) {
Image image = stackImageService.getCurrentImage(stack);
affected = AFFECTED_IMAGE_IDS.contains(image.getImageId());
LOGGER.debug("Stack {} with version {} and image {} is {} by unbound service restart bug", stack.getResourceCrn(), stack.getStackVersion(), image.getImageId(), affected ? "affected" : "not affected");
} else {
LOGGER.debug("Stack {} with version {} is not affected by unbound service restart bug", stack.getResourceCrn(), stack.getStackVersion());
}
return affected;
} catch (CloudbreakImageNotFoundException e) {
LOGGER.warn("Image not found for stack " + stack.getResourceCrn(), e);
throw new CloudbreakRuntimeException("Image not found for stack " + stack.getResourceCrn(), e);
}
}
Aggregations