use of com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGenerator in project cloudbreak by hortonworks.
the class StackStatusCheckerJob method executeTracedJob.
@Override
protected void executeTracedJob(JobExecutionContext context) throws JobExecutionException {
if (flowLogService.isOtherFlowRunning(getStackId())) {
LOGGER.debug("StackStatusCheckerJob cannot run, because flow is running for stack: {}", getStackId());
return;
}
try {
measure(() -> {
Stack stack = stackService.get(getStackId());
Status stackStatus = stack.getStatus();
if (Status.getUnschedulableStatuses().contains(stackStatus)) {
LOGGER.debug("Stack sync will be unscheduled, stack state is {}", stackStatus);
jobService.unschedule(getLocalId());
} else if (shouldSwitchToLongSyncJob(stackStatus, context)) {
LOGGER.debug("Stack sync will be scheduled to long polling, stack state is {}", stackStatus);
jobService.unschedule(getLocalId());
jobService.scheduleLongIntervalCheck(getStackId(), StackJobAdapter.class);
} else if (null == stackStatus || ignoredStates().contains(stackStatus)) {
LOGGER.debug("Stack sync is skipped, stack state is {}", stackStatus);
} else if (syncableStates().contains(stackStatus)) {
RegionAwareInternalCrnGenerator dataHub = regionAwareInternalCrnGeneratorFactory.datahub();
ThreadBasedUserCrnProvider.doAs(dataHub.getInternalCrnForServiceAsString(), () -> doSync(stack));
switchToShortSyncIfNecessary(context);
} else {
LOGGER.warn("Unhandled stack status, {}", stackStatus);
}
}, LOGGER, "Check status took {} ms for stack {}.", getStackId());
} catch (Exception e) {
LOGGER.info("Exception during cluster state check.", e);
}
}
use of com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGenerator in project cloudbreak by hortonworks.
the class InternalCrnBuilderTest method generateCrnAsStringWhenFreeIpaIs.
@Test
public void generateCrnAsStringWhenFreeIpaIs() {
RegionAwareInternalCrnGenerator regionAwareInternalCrnGenerator = regionalAwareInternalCrnGenerator(Crn.Service.FREEIPA, "cdp", "us-west-1");
assertEquals("crn:cdp:freeipa:us-west-1:altus:user:__internal__actor__", regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString());
}
use of com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGenerator in project cloudbreak by hortonworks.
the class FreeIpaServiceTest method upgradeCcmFailureTest.
@Test
void upgradeCcmFailureTest() {
when(freeIpaV1Endpoint.upgradeCcmInternal(ENVCRN, USERCRN)).thenThrow(new WebApplicationException("Houston..."));
RegionAwareInternalCrnGenerator iamGenerator = mock(RegionAwareInternalCrnGenerator.class);
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(iamGenerator);
when(webApplicationExceptionMessageExtractor.getErrorMessage(any())).thenReturn("custom error");
when(iamGenerator.getInternalCrnForServiceAsString()).thenReturn(USERCRN);
assertThatThrownBy(() -> ThreadBasedUserCrnProvider.doAs(USERCRN, () -> underTest.upgradeCcm(ENVCRN))).hasMessage("custom error").isExactlyInstanceOf(FreeIpaOperationFailedException.class);
}
use of com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGenerator in project cloudbreak by hortonworks.
the class CloudStorageManifesterTest method whenEnvironmentHasLoggingEnabledThenShouldApplyAsLogIdentityForGCS.
@Test
public void whenEnvironmentHasLoggingEnabledThenShouldApplyAsLogIdentityForGCS() {
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
mockFileSystemResponseForCloudbreakClient();
SdxCluster sdxCluster = new SdxCluster();
SdxClusterRequest sdxClusterRequest = new SdxClusterRequest();
sdxCluster.setInitiatorUserCrn(USER_CRN);
sdxCluster.setClusterName("sdx-cluster");
SdxCloudStorageRequest cloudStorageRequest = new SdxCloudStorageRequest();
cloudStorageRequest.setBaseLocation("gs://example-path");
cloudStorageRequest.setFileSystemType(FileSystemType.GCS);
GcsCloudStorageV1Parameters gcsCloudStorageV1Parameters = new GcsCloudStorageV1Parameters();
gcsCloudStorageV1Parameters.setServiceAccountEmail(EMAIL);
cloudStorageRequest.setGcs(gcsCloudStorageV1Parameters);
sdxClusterRequest.setCloudStorage(cloudStorageRequest);
DetailedEnvironmentResponse environment = new DetailedEnvironmentResponse();
environment.setCloudPlatform("GCP");
TelemetryResponse telemetryResponse = new TelemetryResponse();
LoggingResponse loggingResponse = new LoggingResponse();
loggingResponse.setGcs(gcsCloudStorageV1Parameters);
telemetryResponse.setLogging(loggingResponse);
GcpEnvironmentParameters gcpEnvironmentParameters = GcpEnvironmentParameters.builder().build();
environment.setGcp(gcpEnvironmentParameters);
environment.setTelemetry(telemetryResponse);
ClusterV4Request clusterV4Request = new ClusterV4Request();
clusterV4Request.setBlueprintName(exampleBlueprintName);
CloudStorageRequest cloudStorageConfigReq = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.initCloudStorageRequest(environment, clusterV4Request, sdxCluster, sdxClusterRequest));
StorageLocationBase singleRequest = cloudStorageConfigReq.getLocations().iterator().next();
assertEquals(2, cloudStorageConfigReq.getIdentities().size());
assertEquals(1, cloudStorageConfigReq.getIdentities().stream().filter(r -> r.getType().equals(CloudIdentityType.ID_BROKER)).collect(Collectors.toSet()).size());
assertEquals(1, cloudStorageConfigReq.getIdentities().stream().filter(r -> r.getType().equals(CloudIdentityType.LOG)).collect(Collectors.toSet()).size());
assertEquals(2, cloudStorageConfigReq.getIdentities().stream().filter(r -> r.getGcs().getServiceAccountEmail().equals(EMAIL)).collect(Collectors.toSet()).size());
assertEquals(1, cloudStorageConfigReq.getLocations().size());
assertEquals(CloudStorageCdpService.RANGER_AUDIT, singleRequest.getType());
assertEquals("ranger/example-path", singleRequest.getValue());
verify(storageValidationService).validateCloudStorage("GCP", cloudStorageRequest);
}
use of com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGenerator in project cloudbreak by hortonworks.
the class CloudStorageManifesterTest method whenEnvironmentHasLoggingEnabledThenShouldApplyAsLogIdentity.
@Test
public void whenEnvironmentHasLoggingEnabledThenShouldApplyAsLogIdentity() {
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
mockFileSystemResponseForCloudbreakClient();
SdxCluster sdxCluster = new SdxCluster();
SdxClusterRequest sdxClusterRequest = new SdxClusterRequest();
sdxCluster.setInitiatorUserCrn(USER_CRN);
sdxCluster.setClusterName("sdx-cluster");
SdxCloudStorageRequest cloudStorageRequest = new SdxCloudStorageRequest();
cloudStorageRequest.setBaseLocation("s3a://example-path");
cloudStorageRequest.setFileSystemType(FileSystemType.S3);
S3CloudStorageV1Parameters s3Params = new S3CloudStorageV1Parameters();
s3Params.setInstanceProfile("instance:profile");
cloudStorageRequest.setS3(s3Params);
sdxClusterRequest.setCloudStorage(cloudStorageRequest);
DetailedEnvironmentResponse environment = new DetailedEnvironmentResponse();
environment.setCloudPlatform("AWS");
TelemetryResponse telemetryResponse = new TelemetryResponse();
LoggingResponse loggingResponse = new LoggingResponse();
S3CloudStorageV1Parameters s3CloudStorageV1Parameters = new S3CloudStorageV1Parameters();
s3CloudStorageV1Parameters.setInstanceProfile("logprofile");
loggingResponse.setS3(s3CloudStorageV1Parameters);
telemetryResponse.setLogging(loggingResponse);
AwsEnvironmentParameters awsEnvironmentParameters = new AwsEnvironmentParameters();
S3GuardRequestParameters s3GuardRequestParameters = new S3GuardRequestParameters();
s3GuardRequestParameters.setDynamoDbTableName("table");
awsEnvironmentParameters.setS3guard(s3GuardRequestParameters);
environment.setAws(awsEnvironmentParameters);
environment.setTelemetry(telemetryResponse);
ClusterV4Request clusterV4Request = new ClusterV4Request();
clusterV4Request.setBlueprintName(exampleBlueprintName);
CloudStorageRequest cloudStorageConfigReq = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.initCloudStorageRequest(environment, clusterV4Request, sdxCluster, sdxClusterRequest));
StorageLocationBase singleRequest = cloudStorageConfigReq.getLocations().iterator().next();
assertEquals(2, cloudStorageConfigReq.getIdentities().size());
assertEquals(1, cloudStorageConfigReq.getIdentities().stream().filter(r -> r.getType().equals(CloudIdentityType.ID_BROKER)).collect(Collectors.toSet()).size());
assertEquals(1, cloudStorageConfigReq.getIdentities().stream().filter(r -> r.getType().equals(CloudIdentityType.LOG)).collect(Collectors.toSet()).size());
assertEquals("table", cloudStorageConfigReq.getAws().getS3Guard().getDynamoTableName());
assertEquals(1, cloudStorageConfigReq.getLocations().size());
assertEquals(CloudStorageCdpService.RANGER_AUDIT, singleRequest.getType());
assertEquals("ranger/example-path", singleRequest.getValue());
verify(storageValidationService).validateCloudStorage("AWS", cloudStorageRequest);
}
Aggregations