Search in sources :

Example 36 with NotFoundException

use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.

the class RepairInstancesService method rebootInstances.

/**
 * If no instance passed in request, reboot all bad instances
 * If instances passed in request, reboot all valid passed bad instances
 * If force and instances passed in request, reboot all valid passed instances
 * If force and no instances passed in request, reboot all instances
 *
 * @param accountId - The account id for the instance to reboot.
 * @param request   - A RebootInstanceRequest containing request parameters.
 */
public OperationStatus rebootInstances(String accountId, RebootInstancesRequest request) {
    Stack stack = stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(request.getEnvironmentCrn(), accountId);
    Map<String, InstanceMetaData> allInstancesByInstanceId = getAllInstancesFromStack(stack);
    Map<String, InstanceStatus> healthMap = request.isForceReboot() ? Collections.emptyMap() : getInstanceHealthMap(accountId, request.getEnvironmentCrn());
    Map<String, InstanceMetaData> instancesToReboot = getInstancesToRepair(healthMap, allInstancesByInstanceId, request.getInstanceIds(), request.isForceReboot(), true);
    if (instancesToReboot.keySet().isEmpty()) {
        throw new NotFoundException("No unhealthy instances to reboot.  Maybe use the force option.");
    }
    Operation operation = operationService.startOperation(accountId, OperationType.REBOOT, Set.of(stack.getEnvironmentCrn()), Collections.emptySet());
    if (operation.getStatus() == OperationState.RUNNING) {
        stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.REPAIR_REQUESTED, "Reboot requested");
        flowManager.notify(REBOOT_EVENT.event(), new RebootInstanceEvent(REBOOT_EVENT.event(), stack.getId(), instancesToReboot.keySet().stream().collect(Collectors.toList()), operation.getOperationId()));
    }
    return operationToOperationStatusConverter.convert(operation);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) RebootInstanceEvent(com.sequenceiq.freeipa.flow.instance.reboot.RebootInstanceEvent) InstanceStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Operation(com.sequenceiq.freeipa.entity.Operation) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 37 with NotFoundException

use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.

the class SecurityGroupBuilderUtilTest method testCreateOrGetSecurityGroupWhenSecurityGroupExistsVpcIdMismatch.

@Test
public void testCreateOrGetSecurityGroupWhenSecurityGroupExistsVpcIdMismatch() {
    String groupId = "groupId";
    String groupName = "groupName";
    CreateSecurityGroupRequest request = new CreateSecurityGroupRequest();
    request.setGroupName(groupName);
    AmazonEC2Exception amazonEC2Exception = new AmazonEC2Exception("Duplicate error");
    amazonEC2Exception.setErrorCode("InvalidGroup.Duplicate");
    when(amazonEc2Client.describeSecurityGroups(any())).thenReturn(new DescribeSecurityGroupsResult().withSecurityGroups(new SecurityGroup().withGroupId(groupId).withGroupName("othergroup").withIpPermissions(new IpPermission())));
    when(amazonEc2Client.createSecurityGroup(request)).thenThrow(amazonEC2Exception);
    NotFoundException actual = Assertions.assertThrows(NotFoundException.class, () -> underTest.createOrGetSecurityGroup(amazonEc2Client, request, group, awsNetworkView, ac));
    Assertions.assertEquals("Aws Security Group 'groupName' not found.", actual.getMessage());
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) IpPermission(com.amazonaws.services.ec2.model.IpPermission) DescribeSecurityGroupsResult(com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult) SecurityGroup(com.amazonaws.services.ec2.model.SecurityGroup) CreateSecurityGroupRequest(com.amazonaws.services.ec2.model.CreateSecurityGroupRequest) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) Test(org.junit.jupiter.api.Test)

Example 38 with NotFoundException

use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.

the class ClouderaManagerModificationServiceTest method testUpgradeClusterComponentIsNotPresent.

@Test
void testUpgradeClusterComponentIsNotPresent() throws ApiException {
    BigDecimal apiCommandId = new BigDecimal(200);
    ApiCommandList apiCommandList = new ApiCommandList();
    apiCommandList.setItems(new ArrayList<>());
    when(clouderaManagerApiFactory.getMgmtServiceResourceApi(any())).thenReturn(mgmtServiceResourceApi);
    when(mgmtServiceResourceApi.listActiveCommands("SUMMARY")).thenReturn(apiCommandList);
    when(mgmtServiceResourceApi.restartCommand()).thenReturn(new ApiCommand().id(apiCommandId));
    when(clouderaManagerPollingServiceProvider.startPollingCmServicesRestart(stack, apiClientMock, apiCommandId)).thenReturn(success);
    when(clouderaManagerPollingServiceProvider.startPollingCmHostStatus(stack, apiClientMock)).thenReturn(success);
    ClouderaManagerRepo clouderaManagerRepo = mock(ClouderaManagerRepo.class);
    when(clusterComponentProvider.getClouderaManagerRepoDetails(CLUSTER_ID)).thenReturn(clouderaManagerRepo);
    when(clouderaManagerRepo.getVersion()).thenReturn(CLOUDERAMANAGER_VERSION_7_5_1.getVersion());
    Set<ClusterComponent> clusterComponents = TestUtil.clusterComponentSet(cluster);
    Set<ClusterComponent> clusterComponentsNoCDH = clusterComponents.stream().filter(clusterComponent -> !clusterComponent.getName().equals("CDH")).collect(Collectors.toSet());
    cluster.setComponents(clusterComponentsNoCDH);
    NotFoundException exception = assertThrows(NotFoundException.class, () -> underTest.upgradeClusterRuntime(clusterComponentsNoCDH, false, Optional.empty()));
    Assertions.assertEquals("Runtime component not found!", exception.getMessage());
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) BeforeEach(org.junit.jupiter.api.BeforeEach) ApiBatchRequestElement(com.cloudera.api.swagger.model.ApiBatchRequestElement) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ApiService(com.cloudera.api.swagger.model.ApiService) ApiException(com.cloudera.api.swagger.client.ApiException) ClouderaManagerProductsProvider(com.sequenceiq.cloudbreak.cluster.service.ClouderaManagerProductsProvider) Mockito.doThrow(org.mockito.Mockito.doThrow) BigDecimal(java.math.BigDecimal) MockitoAnnotations(org.mockito.MockitoAnnotations) ApiCommandList(com.cloudera.api.swagger.model.ApiCommandList) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) ApiHostRefList(com.cloudera.api.swagger.model.ApiHostRefList) CLOUDERAMANAGER_VERSION_7_6_0(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.CLOUDERAMANAGER_VERSION_7_6_0) PollingResultErrorHandler(com.sequenceiq.cloudbreak.cm.polling.PollingResultErrorHandler) Set(java.util.Set) ApiBatchResponse(com.cloudera.api.swagger.model.ApiBatchResponse) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) ApiEntityTag(com.cloudera.api.swagger.model.ApiEntityTag) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) Mock(org.mockito.Mock) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Supplier(java.util.function.Supplier) ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) ClouderaManagerPollingServiceProvider(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerPollingServiceProvider) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) ClouderaManagerApiClientProvider(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerApiClientProvider) CLOUDERAMANAGER_VERSION_7_5_1(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.CLOUDERAMANAGER_VERSION_7_5_1) ApiServiceState(com.cloudera.api.swagger.model.ApiServiceState) ClusterComponentConfigProvider(com.sequenceiq.cloudbreak.cluster.service.ClusterComponentConfigProvider) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) LinkedHashSet(java.util.LinkedHashSet) ValueSource(org.junit.jupiter.params.provider.ValueSource) InjectMocks(org.mockito.InjectMocks) CLOUDERAMANAGER_VERSION_7_1_0(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.CLOUDERAMANAGER_VERSION_7_1_0) Mockito.times(org.mockito.Mockito.times) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) Mockito.never(org.mockito.Mockito.never) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) HTTPMethod(com.cloudera.api.swagger.model.HTTPMethod) ParcelsResourceApi(com.cloudera.api.swagger.ParcelsResourceApi) ClouderaManagerApiFactory(com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) TestUtil(com.sequenceiq.cloudbreak.cm.util.TestUtil) ClouderaManagerProduct(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct) CloudbreakEventService(com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BatchResourceApi(com.cloudera.api.swagger.BatchResourceApi) Spy(org.mockito.Spy) ClouderaManagerResourceApi(com.cloudera.api.swagger.ClouderaManagerResourceApi) HostTemplatesResourceApi(com.cloudera.api.swagger.HostTemplatesResourceApi) CLOUDERAMANAGER_VERSION_7_4_3(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.CLOUDERAMANAGER_VERSION_7_4_3) ParcelResourceApi(com.cloudera.api.swagger.ParcelResourceApi) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) MethodSource(org.junit.jupiter.params.provider.MethodSource) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) ApiBatchResponseElement(com.cloudera.api.swagger.model.ApiBatchResponseElement) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) ApiRestartClusterArgs(com.cloudera.api.swagger.model.ApiRestartClusterArgs) Optional(java.util.Optional) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ApiClient(com.cloudera.api.swagger.client.ApiClient) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) ApiConfigStalenessStatus(com.cloudera.api.swagger.model.ApiConfigStalenessStatus) HashSet(java.util.HashSet) ArgumentCaptor(org.mockito.ArgumentCaptor) UPDATE_IN_PROGRESS(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.UPDATE_IN_PROGRESS) ApiHost(com.cloudera.api.swagger.model.ApiHost) ApiBatchRequest(com.cloudera.api.swagger.model.ApiBatchRequest) InOrder(org.mockito.InOrder) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Assertions(org.junit.jupiter.api.Assertions) Call(com.squareup.okhttp.Call) MgmtServiceResourceApi(com.cloudera.api.swagger.MgmtServiceResourceApi) ApiServiceList(com.cloudera.api.swagger.model.ApiServiceList) Collections(java.util.Collections) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) ApiCommandList(com.cloudera.api.swagger.model.ApiCommandList) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) BigDecimal(java.math.BigDecimal) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 39 with NotFoundException

use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.

the class CustomImageCatalogService method getSourceImage.

public Image getSourceImage(CustomImage image) {
    String imageId = image.getCustomizedImageId();
    LOGGER.debug(String.format("Get source image '%s' from default catalog", imageId));
    try {
        StatedImage sourceStatedImage = imageCatalogService.getSourceImageByImageType(image);
        return sourceStatedImage.getImage();
    } catch (CloudbreakImageNotFoundException | CloudbreakImageCatalogException e) {
        LOGGER.error(String.format("Failed to get source image: %s", e.getMessage()));
        throw new NotFoundException(String.format("Could not find source image with id: '%s'", imageId));
    }
}
Also used : CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)

Example 40 with NotFoundException

use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.

the class StructuredSynchronizerJob method executeTracedJob.

@Override
protected void executeTracedJob(JobExecutionContext context) throws JobExecutionException {
    Long stackId = getLocalIdAsLong();
    try {
        Stack stack = stackService.get(stackId);
        if (stack == null) {
            LOGGER.debug("Stack not found with id {}, StructuredSynchronizerJob will be unscheduled.", stackId);
            syncJobService.unschedule(getLocalId());
        } else if (stack.getStatus() == null) {
            LOGGER.debug("Stack state is null for stack {}. The event won't be stored!", stackId);
        } else if (unschedulableStates().contains(stack.getStatus())) {
            LOGGER.debug("StructuredSynchronizerJob will be unscheduled for stack {}, stack state is {}", stackId, stack.getStatus());
            syncJobService.unschedule(getLocalId());
        } else {
            LOGGER.debug("StructuredSynchronizerJob is running for stack: '{}'", stackId);
            StructuredSyncEvent structuredEvent = structuredSyncEventFactory.createStructuredSyncEvent(stackId);
            legacyDefaultStructuredEventClient.sendStructuredEvent(structuredEvent);
        }
    } catch (NotFoundException ex) {
        LOGGER.debug("Stack not found with id {}, StructuredSynchronizerJob will be unscheduled.", stackId);
        syncJobService.unschedule(getLocalId());
    } catch (Exception ex) {
        LOGGER.error("Error happened during StructuredSyncEvent generation! The event won't be stored!", ex);
    }
}
Also used : StructuredSyncEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredSyncEvent) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) JobExecutionException(org.quartz.JobExecutionException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Aggregations

NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)73 Test (org.junit.jupiter.api.Test)33 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)11 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)10 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)9 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)8 Map (java.util.Map)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)6 List (java.util.List)6 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)5 TransactionRuntimeExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)5 Workspace (com.sequenceiq.cloudbreak.workspace.model.Workspace)5 Optional (java.util.Optional)5 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)4 Set (java.util.Set)4 CheckPermissionByResourceName (com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)3 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)3