Search in sources :

Example 6 with Resource

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());
}
Also used : Resource(com.sequenceiq.cloudbreak.domain.Resource) ResourceType(com.sequenceiq.cloudbreak.common.type.ResourceType) Matchers.anyString(org.mockito.Matchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) InvocationOnMock(org.mockito.invocation.InvocationOnMock) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Test(org.junit.Test)

Example 7 with Resource

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;
}
Also used : Resource(com.sequenceiq.cloudbreak.domain.Resource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourceRepository(com.sequenceiq.cloudbreak.repository.ResourceRepository)

Example 8 with Resource

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;
}
Also used : Resource(com.sequenceiq.cloudbreak.domain.Resource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourceRepository(com.sequenceiq.cloudbreak.repository.ResourceRepository)

Aggregations

Resource (com.sequenceiq.cloudbreak.domain.Resource)8 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)5 ResourceRepository (com.sequenceiq.cloudbreak.repository.ResourceRepository)3 Stack (com.sequenceiq.cloudbreak.domain.Stack)2 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)1 ResourceType (com.sequenceiq.cloudbreak.common.type.ResourceType)1 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)1 FailurePolicy (com.sequenceiq.cloudbreak.domain.FailurePolicy)1 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)1 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)1 Network (com.sequenceiq.cloudbreak.domain.Network)1 Orchestrator (com.sequenceiq.cloudbreak.domain.Orchestrator)1 StackAuthentication (com.sequenceiq.cloudbreak.domain.StackAuthentication)1 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1