use of com.sequenceiq.cloudbreak.domain.Resource in project cloudbreak by hortonworks.
the class ClusterBootstrapperErrorHandlerTest method clusterBootstrapErrorHandlerWhenNodeCountHigherThanZeroAfterTheRollbackThenClusterProvisionFailed.
@Test
public void clusterBootstrapErrorHandlerWhenNodeCountHigherThanZeroAfterTheRollbackThenClusterProvisionFailed() 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());
doNothing().when(resourceRepository).delete(anyLong());
when(resourceRepository.findByStackIdAndNameAndType(anyLong(), anyString(), any(ResourceType.class))).thenReturn(new Resource());
when(connector.removeInstances(any(Stack.class), anySet(), anyString())).thenReturn(new HashSet<>());
when(instanceMetaDataRepository.findNotTerminatedByPrivateAddress(anyLong(), anyString())).thenAnswer(new Answer<InstanceMetaData>() {
@Override
public InstanceMetaData answer(InvocationOnMock 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(new Answer<InstanceGroup>() {
@Override
public InstanceGroup answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
String name = (String) args[1];
for (InstanceMetaData instanceMetaData : stack.getRunningInstanceMetaData()) {
if (instanceMetaData.getInstanceGroup().getGroupName().equals(name)) {
InstanceGroup instanceGroup = instanceMetaData.getInstanceGroup();
instanceGroup.setNodeCount(2);
return instanceGroup;
}
}
return null;
}
});
underTest.terminateFailedNodes(null, orchestrator, TestUtil.stack(), new GatewayConfig("10.0.0.1", "198.0.0.1", "10.0.0.1", 8443, false), prepareNodes(stack));
verify(eventService, times(4)).fireCloudbreakEvent(anyLong(), anyString(), anyString());
verify(instanceGroupRepository, times(3)).save(any(InstanceGroup.class));
verify(instanceMetaDataRepository, times(3)).save(any(InstanceMetaData.class));
verify(connector, times(3)).removeInstances(any(Stack.class), anySet(), anyString());
verify(resourceRepository, times(3)).findByStackIdAndNameAndType(anyLong(), anyString(), any(ResourceType.class));
verify(resourceRepository, times(3)).delete(anyLong());
verify(instanceGroupRepository, times(3)).findOneByGroupNameInStack(anyLong(), anyString());
}
use of com.sequenceiq.cloudbreak.domain.Resource in project cloudbreak by hortonworks.
the class CloudResourcePersisterService method persist.
@Override
public ResourceNotification persist(ResourceNotification notification) {
LOGGER.debug("Resource allocation notification received: {}", notification);
Long stackId = notification.getCloudContext().getId();
CloudResource cloudResource = notification.getCloudResource();
Resource resource = getConversionService().convert(cloudResource, Resource.class);
ResourceRepository resourceRepository = getResourceRepository();
Resource persistedResource = resourceRepository.findByStackIdAndNameAndType(stackId, cloudResource.getName(), cloudResource.getType());
if (persistedResource != null) {
LOGGER.warn("Trying to persist a resource (name: {}, type: {}, stackId: {}) that is already persisted, skipping..", cloudResource.getName(), cloudResource.getType().name(), stackId);
return notification;
}
resource.setStack(getStackRepository().findOne(stackId));
resourceRepository.save(resource);
return notification;
}
use of com.sequenceiq.cloudbreak.domain.Resource in project cloudbreak by hortonworks.
the class CloudResourcePersisterService method update.
@Override
public ResourceNotification update(ResourceNotification notification) {
LOGGER.debug("Resource update notification received: {}", notification);
Long stackId = notification.getCloudContext().getId();
CloudResource cloudResource = notification.getCloudResource();
ResourceRepository repository = getResourceRepository();
Resource persistedResource = repository.findByStackIdAndNameAndType(stackId, cloudResource.getName(), cloudResource.getType());
Resource resource = getConversionService().convert(cloudResource, Resource.class);
updateWithPersistedFields(resource, persistedResource);
resource.setStack(getStackRepository().findOne(stackId));
repository.save(resource);
return notification;
}
Aggregations