use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_UNHEALTHY in project cloudbreak by hortonworks.
the class InstanceMetadataUpdaterTest method updatePackageVersionsOnAllInstancesInstancePkgQueryFailed.
@Test
public void updatePackageVersionsOnAllInstancesInstancePkgQueryFailed() throws Exception {
Stack stack = createStack();
Map<String, Map<String, String>> hostPackageMap = Maps.newHashMap();
hostPackageMap.put("instanceId", packageMap());
hostPackageMap.put("hostByCmd", falsePackageMap());
when(hostOrchestrator.getPackageVersionsFromAllHosts(any(GatewayConfig.class), any())).thenReturn(hostPackageMap);
when(stackService.getByIdWithListsInTransaction(anyLong())).thenReturn(stack);
underTest.updatePackageVersionsOnAllInstances(1L);
verify(cloudbreakEventService, times(1)).fireCloudbreakEvent(anyLong(), anyString(), eq(ResourceEvent.CLUSTER_PACKAGE_VERSION_CANNOT_BE_QUERIED), anyCollection());
verify(cloudbreakEventService, times(2)).fireCloudbreakEvent(anyLong(), anyString(), any(ResourceEvent.class), anyCollection());
assertEquals(SERVICES_UNHEALTHY, stack.getInstanceGroups().stream().filter(instanceGroup -> instanceGroup.getInstanceMetaDataSet().stream().filter(instanceMetaData -> StringUtils.equals(instanceMetaData.getDiscoveryFQDN(), "hostByCmd")).findFirst().isPresent()).findFirst().get().getInstanceMetaDataSet().iterator().next().getInstanceStatus());
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_UNHEALTHY in project cloudbreak by hortonworks.
the class ClusterOperationService method updateFailedNodes.
private void updateFailedNodes(Cluster cluster, Map<InstanceMetaData, Optional<String>> failedHostMetadata) throws TransactionExecutionException {
if (!failedHostMetadata.isEmpty()) {
Map<String, Optional<String>> hostNamesWithReason = failedHostMetadata.entrySet().stream().filter(e -> e.getKey().getDiscoveryFQDN() != null).collect(Collectors.toMap(e -> e.getKey().getDiscoveryFQDN(), e -> e.getValue()));
Set<InstanceStatus> expectedStates = Set.of(SERVICES_HEALTHY, SERVICES_RUNNING);
InstanceStatus newState = SERVICES_UNHEALTHY;
ResourceEvent clusterEvent = CLUSTER_FAILED_NODES_REPORTED_CLUSTER_EVENT;
ResourceEvent hostEvent = CLUSTER_FAILED_NODES_REPORTED_HOST_EVENT;
updateChangedHosts(cluster, hostNamesWithReason, expectedStates, newState, clusterEvent, Optional.of(hostEvent));
}
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_UNHEALTHY in project cloudbreak by hortonworks.
the class ClusterOperationService method updateNewHealthyNodes.
private void updateNewHealthyNodes(Cluster cluster, Set<String> newHealthyNodes) throws TransactionExecutionException {
if (!newHealthyNodes.isEmpty()) {
Map<String, Optional<String>> hostNamesWithReason = newHealthyNodes.stream().collect(Collectors.toMap(host -> host, host -> Optional.empty()));
Set<InstanceStatus> expectedStates = EnumSet.of(SERVICES_UNHEALTHY, SERVICES_RUNNING, DECOMMISSION_FAILED, FAILED);
InstanceStatus newState = SERVICES_HEALTHY;
ResourceEvent clusterEvent = CLUSTER_RECOVERED_NODES_REPORTED_CLUSTER_EVENT;
updateChangedHosts(cluster, hostNamesWithReason, expectedStates, newState, clusterEvent, Optional.empty());
}
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_UNHEALTHY in project cloudbreak by hortonworks.
the class MockStackResponseGenerator method getMockStackV4Response.
public static StackV4Response getMockStackV4Response(String clusterCrn, String hostGroup, String fqdnBase, int currentHostGroupCount, boolean withUnhealthyInstances) {
List<InstanceGroupV4Response> instanceGroupV4Responses = new ArrayList<>();
InstanceMetaDataV4Response master1 = new InstanceMetaDataV4Response();
master1.setDiscoveryFQDN("master1");
master1.setInstanceId("test_instanceid" + "master1");
instanceGroupV4Responses.add(instanceGroup("master", awsTemplate(), Set.of(master1)));
InstanceMetaDataV4Response worker1 = new InstanceMetaDataV4Response();
worker1.setDiscoveryFQDN("worker1");
worker1.setInstanceId("test_instanceid" + "worker1");
InstanceMetaDataV4Response worker2 = new InstanceMetaDataV4Response();
worker2.setDiscoveryFQDN("worker2");
worker2.setInstanceId("test_instanceid" + "worker2");
instanceGroupV4Responses.add(instanceGroup("worker", awsTemplate(), Set.of(worker1, worker2)));
Set fqdnToInstanceIds = new HashSet();
if (!withUnhealthyInstances) {
for (int i = 1; i <= currentHostGroupCount; i++) {
InstanceMetaDataV4Response metadata1 = new InstanceMetaDataV4Response();
metadata1.setDiscoveryFQDN(fqdnBase + i);
metadata1.setInstanceId("test_instanceid_" + hostGroup + i);
metadata1.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
fqdnToInstanceIds.add(metadata1);
}
} else {
// Add nodes with InstanceStatuses STOPPED and SERVICES_UNHEALTHY
List<InstanceStatus> unhealthyStatuses = List.of(InstanceStatus.STOPPED, InstanceStatus.SERVICES_UNHEALTHY);
for (InstanceStatus status : unhealthyStatuses) {
InstanceMetaDataV4Response metadataResponse = new InstanceMetaDataV4Response();
metadataResponse.setDiscoveryFQDN(fqdnBase + unhealthyStatuses.indexOf(status));
metadataResponse.setInstanceId("test_instanceid_" + hostGroup + unhealthyStatuses.indexOf(status));
metadataResponse.setInstanceStatus(status);
fqdnToInstanceIds.add(metadataResponse);
}
// Add remaining healthy instances
for (int i = unhealthyStatuses.size(); i < currentHostGroupCount; ++i) {
InstanceMetaDataV4Response metadataResponse = new InstanceMetaDataV4Response();
metadataResponse.setDiscoveryFQDN(fqdnBase + i);
metadataResponse.setInstanceId("test_instanceid_" + hostGroup + i);
metadataResponse.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
fqdnToInstanceIds.add(metadataResponse);
}
}
instanceGroupV4Responses.add(instanceGroup(hostGroup, awsTemplate(), fqdnToInstanceIds));
StackV4Response mockReponse = new StackV4Response();
mockReponse.setCrn(clusterCrn);
mockReponse.setInstanceGroups(instanceGroupV4Responses);
mockReponse.setCloudPlatform(CloudPlatform.AWS);
return mockReponse;
}
Aggregations