use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.
the class UnhealthyInstancesDetectionHandlerTest method shouldCreateResponseWithExactInstances.
@Test
public void shouldCreateResponseWithExactInstances() throws CloudbreakSecuritySetupException {
long stackId = 1L;
UnhealthyInstancesDetectionRequest unhealthyInstancesDetectionRequest = new UnhealthyInstancesDetectionRequest(stackId);
Event event = mock(Event.class);
when(event.getData()).thenReturn(unhealthyInstancesDetectionRequest);
Stack stack = mock(Stack.class);
when(stackService.getById(stackId)).thenReturn(stack);
Set<InstanceMetaData> unhealthyInstances = new HashSet<>();
InstanceMetaData imd1 = mock(InstanceMetaData.class);
InstanceMetaData imd2 = mock(InstanceMetaData.class);
InstanceMetaData imd3 = mock(InstanceMetaData.class);
unhealthyInstances.add(imd1);
unhealthyInstances.add(imd2);
unhealthyInstances.add(imd3);
when(candidateUnhealthyInstanceSelector.selectCandidateUnhealthyInstances(stack.getId())).thenReturn(unhealthyInstances);
Set<String> unhealthyInstanceIds = new HashSet<>();
unhealthyInstanceIds.add("i-0f1e0605506aaaaaa");
unhealthyInstanceIds.add("i-0f1e0605506cccccc");
when(unhealthyInstancesFinalizer.finalizeUnhealthyInstances(stack, unhealthyInstances)).thenReturn(unhealthyInstanceIds);
unhealthyInstancesDetectionHandler.accept(event);
verify(eventBus).notify(eq(EventSelectorUtil.selector(UnhealthyInstancesDetectionResult.class)), argThat(new UnhealthyInstancesResultMatcher(unhealthyInstanceIds)));
}
use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.
the class AmbariClusterHostServiceTypeTest method testUpdateHostsForDownscaleFilterOneHost.
@Test
public void testUpdateHostsForDownscaleFilterOneHost() throws CloudbreakSecuritySetupException {
HostGroupAdjustmentJson json = new HostGroupAdjustmentJson();
json.setHostGroup("slave_1");
json.setScalingAdjustment(-1);
AmbariClient ambariClient = mock(AmbariClient.class);
HostMetadata metadata1 = mock(HostMetadata.class);
InstanceMetaData instanceMetaData1 = mock(InstanceMetaData.class);
HostMetadata metadata2 = mock(HostMetadata.class);
InstanceMetaData instanceMetaData2 = mock(InstanceMetaData.class);
HostMetadata metadata3 = mock(HostMetadata.class);
InstanceMetaData instanceMetaData3 = mock(InstanceMetaData.class);
HostMetadata metadata4 = mock(HostMetadata.class);
InstanceMetaData instanceMetaData4 = mock(InstanceMetaData.class);
Set<HostMetadata> hostsMetaData = new HashSet<>(asList(metadata1, metadata2, metadata3, metadata4));
HostGroup hostGroup = new HostGroup();
hostGroup.setHostMetadata(hostsMetaData);
hostGroup.setName("slave_1");
Map<String, Map<Long, Long>> dfsSpace = new HashMap<>();
dfsSpace.put("node2", singletonMap(85_000L, 15_000L));
dfsSpace.put("node1", singletonMap(90_000L, 10_000L));
dfsSpace.put("node3", singletonMap(80_000L, 20_000L));
dfsSpace.put("node4", singletonMap(80_000L, 11_000L));
when(metadata1.getHostName()).thenReturn("node1");
when(metadata2.getHostName()).thenReturn("node2");
when(metadata3.getHostName()).thenReturn("node3");
when(metadata4.getHostName()).thenReturn("node4");
when(instanceMetaData1.getAmbariServer()).thenReturn(false);
when(instanceMetaData2.getAmbariServer()).thenReturn(false);
when(instanceMetaData3.getAmbariServer()).thenReturn(false);
when(instanceMetaData4.getAmbariServer()).thenReturn(false);
when(ambariClientProvider.getAmbariClient(any(HttpClientConfig.class), anyInt(), any(Cluster.class))).thenReturn(ambariClient);
when(ambariClient.getComponentsCategory("multi-node-yarn", "slave_1")).thenReturn(singletonMap("DATANODE", "SLAVE"));
when(ambariClient.getBlueprintMap(cluster.getBlueprint().getAmbariName())).thenReturn(singletonMap("slave_1", singletonList("DATANODE")));
when(ambariClient.getDFSSpace()).thenReturn(dfsSpace);
when(instanceMetadataRepository.findHostInStack(stack.getId(), "node1")).thenReturn(instanceMetaData1);
when(instanceMetadataRepository.findHostInStack(stack.getId(), "node2")).thenReturn(instanceMetaData2);
when(instanceMetadataRepository.findHostInStack(stack.getId(), "node3")).thenReturn(instanceMetaData3);
when(instanceMetadataRepository.findHostInStack(stack.getId(), "node4")).thenReturn(instanceMetaData4);
when(hostGroupService.getByClusterIdAndName(anyLong(), anyString())).thenReturn(hostGroup);
when(statusToPollGroupConverter.convert(any(Status.class))).thenReturn(PollGroup.POLLABLE);
underTest.updateHosts(stack.getId(), json);
verify(flowManager, times(1)).triggerClusterDownscale(stack.getId(), json);
verify(blueprintValidator, times(1)).validateHostGroupScalingRequest(stack.getCluster().getBlueprint(), hostGroup, json.getScalingAdjustment());
}
use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.
the class ClusterBootstrapperErrorHandlerTest method clusterBootstrapErrorHandlerWhenNodeCountLessThanOneAfterTheRollbackThenClusterProvisionFailed.
@Test
public void clusterBootstrapErrorHandlerWhenNodeCountLessThanOneAfterTheRollbackThenClusterProvisionFailed() throws CloudbreakOrchestratorFailedException {
Stack stack = TestUtil.stack();
doNothing().when(eventService).fireCloudbreakEvent(anyLong(), anyString(), anyString());
when(orchestrator.getAvailableNodes(any(GatewayConfig.class), anySet())).thenReturn(new ArrayList<>());
when(instanceGroupRepository.save(any(InstanceGroup.class))).then(returnsFirstArg());
when(instanceMetaDataRepository.save(any(InstanceMetaData.class))).then(returnsFirstArg());
when(instanceMetaDataRepository.findNotTerminatedByPrivateAddress(anyLong(), anyString())).thenAnswer((Answer<InstanceMetaData>) invocation -> {
Object[] args = invocation.getArguments();
String ip = (String) args[1];
for (InstanceMetaData instanceMetaData : stack.getRunningInstanceMetaData()) {
if (instanceMetaData.getPrivateIp().equals(ip)) {
return instanceMetaData;
}
}
return null;
});
when(instanceGroupRepository.findOneByGroupNameInStack(anyLong(), anyString())).thenAnswer((Answer<InstanceGroup>) invocation -> {
Object[] args = invocation.getArguments();
String name = (String) args[1];
for (InstanceMetaData instanceMetaData : stack.getRunningInstanceMetaData()) {
if (instanceMetaData.getInstanceGroup().getGroupName().equals(name)) {
return instanceMetaData.getInstanceGroup();
}
}
return null;
});
when(cloudbreakMessagesService.getMessage(eq("bootstrapper.error.invalide.nodecount"), any())).thenReturn("invalide.nodecount");
thrown.expect(CloudbreakOrchestratorFailedException.class);
thrown.expectMessage("invalide.nodecount");
underTest.terminateFailedNodes(null, orchestrator, TestUtil.stack(), new GatewayConfig("10.0.0.1", "198.0.0.1", "10.0.0.1", 8443, false), prepareNodes(stack));
}
use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.
the class StackDownscaleActions method stackDownscaleCollectResourcesAction.
@Bean(name = "DOWNSCALE_COLLECT_RESOURCES_STATE")
public Action<?, ?> stackDownscaleCollectResourcesAction() {
return new AbstractStackDownscaleAction<StackDownscaleTriggerEvent>(StackDownscaleTriggerEvent.class) {
@Override
protected void doExecute(StackScalingFlowContext context, StackDownscaleTriggerEvent payload, Map<Object, Object> variables) {
stackDownscaleService.startStackDownscale(context, payload);
Stack stack = context.getStack();
LOGGER.debug("Assembling downscale stack event for stack: {}", stack);
List<CloudResource> resources = cloudResourceConverter.convert(stack.getResources());
variables.put(RESOURCES, resources);
List<CloudInstance> instances = new ArrayList<>();
InstanceGroup group = stack.getInstanceGroupByInstanceGroupName(context.getInstanceGroupName());
for (InstanceMetaData metaData : group.getAllInstanceMetaData()) {
if (context.getInstanceIds().contains(metaData.getInstanceId())) {
CloudInstance cloudInstance = metadataConverter.convert(metaData);
instances.add(cloudInstance);
}
}
variables.put(INSTANCES, instances);
Selectable request = new DownscaleStackCollectResourcesRequest(context.getCloudContext(), context.getCloudCredential(), context.getCloudStack(), resources, instances);
sendEvent(context.getFlowId(), request);
}
};
}
use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.
the class InstanceTerminationService method instanceTermination.
public void instanceTermination(InstanceTerminationContext context) {
Stack stack = context.getStack();
stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.REMOVE_INSTANCE, "Removing instance");
flowMessageService.fireEventAndLog(stack.getId(), Msg.STACK_REMOVING_INSTANCE, UPDATE_IN_PROGRESS.name());
List<InstanceMetaData> instanceMetaDataList = context.getInstanceMetaDataList();
for (InstanceMetaData instanceMetaData : instanceMetaDataList) {
String hostName = instanceMetaData.getDiscoveryFQDN();
if (stack.getCluster() != null) {
HostMetadata hostMetadata = hostMetadataRepository.findHostInClusterByName(stack.getCluster().getId(), hostName);
if (hostMetadata == null) {
LOGGER.info("Nothing to remove since hostmetadata is null");
} else if (HostMetadataState.HEALTHY.equals(hostMetadata.getHostMetadataState())) {
throw new ScalingFailedException(String.format("Host (%s) is in HEALTHY state. Cannot be removed.", hostName));
}
}
if (hostName != null) {
String instanceGroupName = instanceMetaData.getInstanceGroup().getGroupName();
flowMessageService.fireEventAndLog(stack.getId(), Msg.STACK_SCALING_TERMINATING_HOST_FROM_HOSTGROUP, UPDATE_IN_PROGRESS.name(), hostName, instanceGroupName);
}
}
}
Aggregations