use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.
the class InstanceMetaDataService method saveInstanceAndGetUpdatedStack.
public Stack saveInstanceAndGetUpdatedStack(Stack stack, Map<String, Integer> hostGroupsWithInstanceCountToCreate, Map<String, Set<String>> hostGroupWithHostnames, boolean save, boolean repair, NetworkScaleDetails networkScaleDetails) {
LOGGER.info("Get updated stack with instance count ({}) and hostnames: {} and save: ({})", hostGroupsWithInstanceCountToCreate, hostGroupWithHostnames, save);
DetailedEnvironmentResponse environment = getDetailedEnvironmentResponse(stack.getEnvironmentCrn());
Map<String, String> subnetAzPairs = multiAzCalculatorService.prepareSubnetAzMap(environment);
String stackSubnetId = getStackSubnetIdIfExists(stack);
String stackAz = stackSubnetId == null ? null : subnetAzPairs.get(stackSubnetId);
long privateId = getFirstValidPrivateId(stack.getInstanceGroupsAsList());
for (Map.Entry<String, Integer> hostGroupWithInstanceCount : hostGroupsWithInstanceCountToCreate.entrySet()) {
String hostGroup = hostGroupWithInstanceCount.getKey();
Integer instanceToCreate = hostGroupWithInstanceCount.getValue();
Iterator<String> hostNameIterator = getHostNameIterator(hostGroupWithHostnames.get(hostGroup));
for (int i = 0; i < instanceToCreate; i++) {
InstanceGroup instanceGroup = getInstanceGroup(stack.getInstanceGroups(), hostGroup);
if (instanceGroup != null) {
InstanceMetaData instanceMetaData = new InstanceMetaData();
instanceMetaData.setPrivateId(privateId++);
instanceMetaData.setInstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.REQUESTED);
instanceMetaData.setInstanceGroup(instanceGroup);
instanceMetaData.setVariant(stack.getPlatformVariant());
if (hostNameIterator.hasNext()) {
String hostName = hostNameIterator.next();
repository.findHostInStack(stack.getId(), hostName).ifPresent(existingHost -> {
throw new CloudbreakServiceException("There is an existing host with the same FQDN. It can happen if you retried a failed repair. " + "Please start the repairing process again instead of retry.");
});
LOGGER.info("We have hostname to be allocated: {}, set it to this instanceMetadata: {}", hostName, instanceMetaData);
instanceMetaData.setDiscoveryFQDN(hostName);
subnetAzPairs = getSubnetAzPairsFilteredByHostNameIfRepair(environment, stack, repair, instanceGroup.getGroupName(), hostName);
}
Map<String, String> filteredSubnetsByLeastUsedAz = networkScaleDetails == null ? multiAzCalculatorService.filterSubnetByLeastUsedAz(instanceGroup, subnetAzPairs) : subnetAzPairs;
prepareInstanceMetaDataSubnetAndAvailabilityZoneAndRackId(instanceGroup, instanceMetaData, filteredSubnetsByLeastUsedAz, stackSubnetId, stackAz, networkScaleDetails);
if (save) {
repository.save(instanceMetaData);
}
instanceGroup.getInstanceMetaDataSet().add(instanceMetaData);
}
}
}
return stack;
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.
the class InstanceMetaDataService method saveInstanceRequests.
public void saveInstanceRequests(Stack stack, List<Group> groups) {
Set<InstanceGroup> instanceGroups = stack.getInstanceGroups();
for (Group group : groups) {
InstanceGroup instanceGroup = getInstanceGroup(instanceGroups, group.getName());
List<InstanceMetaData> existingInGroup = repository.findAllByInstanceGroupAndInstanceStatus(instanceGroup, com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.REQUESTED);
for (CloudInstance cloudInstance : group.getInstances()) {
InstanceTemplate instanceTemplate = cloudInstance.getTemplate();
boolean exists = existingInGroup.stream().anyMatch(i -> i.getPrivateId().equals(instanceTemplate.getPrivateId()));
if (com.sequenceiq.cloudbreak.cloud.model.InstanceStatus.CREATE_REQUESTED == instanceTemplate.getStatus() && !exists) {
InstanceMetaData instanceMetaData = new InstanceMetaData();
instanceMetaData.setPrivateId(instanceTemplate.getPrivateId());
instanceMetaData.setInstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.REQUESTED);
instanceMetaData.setInstanceGroup(instanceGroup);
instanceMetaData.setVariant(stack.getPlatformVariant());
repository.save(instanceMetaData);
}
}
}
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.
the class TlsSetupService method setupTls.
public void setupTls(Stack stack, InstanceMetaData gwInstance) throws CloudbreakException {
try {
SavingX509TrustManager x509TrustManager = new SavingX509TrustManager();
TrustManager[] trustManagers = { x509TrustManager };
SSLContext sslContext = SslConfigurator.newInstance().createSSLContext();
sslContext.init(null, trustManagers, new SecureRandom());
Client client = RestClientUtil.createClient(sslContext, false);
Integer gatewayPort = stack.getGatewayPort();
String ip = gatewayConfigService.getGatewayIp(stack, gwInstance);
LOGGER.debug("Trying to fetch the server's certificate: {}:{}", ip, gatewayPort);
nginxPollerService.pollWithAbsoluteTimeout(nginxCertListenerTask, new NginxPollerObject(client, ip, gatewayPort, x509TrustManager), POLLING_INTERVAL, TEN_MIN, MAX_FAILURE);
WebTarget nginxTarget = client.target(String.format("https://%s:%d", ip, gatewayPort));
nginxTarget.path("/").request().get().close();
X509Certificate[] chain = x509TrustManager.getChain();
String serverCert = PkiUtil.convert(chain[0]);
InstanceMetaData metaData = getInstanceMetaData(gwInstance);
metaData.setServerCert(BaseEncoding.base64().encode(serverCert.getBytes()));
instanceMetaDataService.save(metaData);
} catch (Exception e) {
throw new CloudbreakException("Failed to retrieve the server's certificate from Nginx." + " Please check your security group is open enough and the Management Console can access your VPC and subnet." + " Please also Make sure your Subnets can route to the internet and you have public DNS and IP options enabled." + " Refer to Cloudera documentation at" + " https://docs.cloudera.com/management-console/cloud/proxy/topics/mc-outbound-internet-access-and-proxy.html", e);
}
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.
the class UnhealthyInstancesFinalizer method finalizeUnhealthyInstances.
public Set<String> finalizeUnhealthyInstances(Stack stack, Iterable<InstanceMetaData> candidateUnhealthyInstances) {
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = CloudContext.Builder.builder().withId(stack.getId()).withName(stack.getName()).withCrn(stack.getResourceCrn()).withPlatform(stack.getCloudPlatform()).withVariant(stack.getPlatformVariant()).withLocation(location).withWorkspaceId(stack.getWorkspace().getId()).withAccountId(Crn.safeFromString(stack.getResourceCrn()).getAccountId()).withTenantId(stack.getTenant().getId()).build();
CloudCredential cloudCredential = stackUtil.getCloudCredential(stack);
List<CloudInstance> cloudInstances = cloudInstanceConverter.convert(candidateUnhealthyInstances, stack.getEnvironmentCrn(), stack.getStackAuthentication());
List<CloudVmInstanceStatus> cloudVmInstanceStatuses = instanceStateQuery.getCloudVmInstanceStatuses(cloudCredential, cloudContext, cloudInstances);
Map<String, CloudVmInstanceStatus> cloudVmInstanceStatusesById = new HashMap<>();
cloudVmInstanceStatuses.forEach(c -> cloudVmInstanceStatusesById.put(c.getCloudInstance().getInstanceId(), c));
Set<String> unhealthyInstances = new HashSet<>();
for (InstanceMetaData i : candidateUnhealthyInstances) {
CloudVmInstanceStatus instanceStatus = cloudVmInstanceStatusesById.get(i.getInstanceId());
if ((instanceStatus == null) || (instanceStatus.getStatus().equals(InstanceStatus.TERMINATED))) {
unhealthyInstances.add(i.getInstanceId());
}
}
return unhealthyInstances;
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData in project cloudbreak by hortonworks.
the class LoggingAgentAutoRestartPatchService method doApply.
@Override
boolean doApply(Stack stack) throws ExistingStackPatchApplyException {
if (isPrimaryGatewayReachable(stack)) {
try {
byte[] currentSaltState = getCurrentSaltStateStack(stack);
List<String> saltStateDefinitions = Arrays.asList("salt-common", "salt");
List<String> loggingAgentSaltStateDef = List.of("/salt/fluent");
byte[] fluentSaltStateConfig = compressUtil.generateCompressedOutputFromFolders(saltStateDefinitions, loggingAgentSaltStateDef);
boolean loggingAgentContentMatches = compressUtil.compareCompressedContent(currentSaltState, fluentSaltStateConfig, loggingAgentSaltStateDef);
if (!loggingAgentContentMatches) {
Set<InstanceMetaData> instanceMetaDataSet = instanceMetaDataService.findNotTerminatedAndNotZombieForStack(stack.getId());
List<GatewayConfig> gatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
ClusterDeletionBasedExitCriteriaModel exitModel = ClusterDeletionBasedExitCriteriaModel.nonCancellableModel();
Set<Node> availableNodes = getAvailableNodes(instanceMetaDataSet, gatewayConfigs, exitModel);
if (CollectionUtils.isEmpty(availableNodes)) {
LOGGER.info("Not found any available nodes for patch, stack: " + stack.getName());
return false;
} else {
getTelemetryOrchestrator().executeLoggingAgentDiagnostics(fluentSaltStateConfig, gatewayConfigs, availableNodes, exitModel);
byte[] newFullSaltState = compressUtil.updateCompressedOutputFolders(saltStateDefinitions, loggingAgentSaltStateDef, currentSaltState);
clusterBootstrapper.updateSaltComponent(stack, newFullSaltState);
LOGGER.debug("Logging agent partial salt refresh and diagnostics successfully finished for stack {}", stack.getName());
return true;
}
} else {
LOGGER.debug("Logging agent partial salt refresh and diagnostics is not required for stack {}", stack.getName());
return true;
}
} catch (ExistingStackPatchApplyException e) {
throw e;
} catch (Exception e) {
throw new ExistingStackPatchApplyException(e.getMessage(), e);
}
} else {
LOGGER.info("Salt partial update cannot run, because primary gateway is unreachable of stack: " + stack.getResourceCrn());
return false;
}
}
Aggregations