Search in sources :

Example 6 with AltusCredential

use of com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential in project cloudbreak by hortonworks.

the class TelemetryDecoratorTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    AltusCredential altusCredential = new AltusCredential("myAccessKey", "mySecretKey".toCharArray());
    DataBusCredential dataBusCredential = new DataBusCredential();
    dataBusCredential.setAccessKey("myAccessKey");
    dataBusCredential.setPrivateKey("mySecretKey");
    given(altusMachineUserService.isMeteringOrAnyDataBusBasedFeatureSupported(any(Stack.class), any(Telemetry.class))).willReturn(true);
    given(altusMachineUserService.storeDataBusCredential(any(Optional.class), any(Stack.class))).willReturn(dataBusCredential);
    given(altusMachineUserService.generateDatabusMachineUserForFluent(any(Stack.class), any(Telemetry.class))).willReturn(Optional.of(altusCredential));
    given(vmLogsService.getVmLogs()).willReturn(new ArrayList<>());
    underTest = new TelemetryDecorator(databusConfigService, fluentConfigService, meteringConfigService, monitoringConfigService, nodeStatusConfigService, telemetryCommonConfigService, altusMachineUserService, vmLogsService, entitlementService, dataBusEndpointProvider, "1.0.0");
}
Also used : Optional(java.util.Optional) AltusCredential(com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential) Telemetry(com.sequenceiq.common.api.telemetry.model.Telemetry) DataBusCredential(com.sequenceiq.common.api.telemetry.model.DataBusCredential) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Before(org.junit.Before)

Example 7 with AltusCredential

use of com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential in project cloudbreak by hortonworks.

the class AltusMachineUserService method getOrCreateDataBusCredentialIfNeeded.

/**
 * Gather or create DataBus credential for a stack.
 * On creation it will generate aa new workload user with new access/private keys.
 * @param stackId id of the stack
 * @return databus credential holder
 */
public DataBusCredential getOrCreateDataBusCredentialIfNeeded(Long stackId) throws IOException {
    LOGGER.debug("Get or create databus credential for stack");
    Stack stack = stackService.get(stackId);
    Cluster cluster = clusterService.findOneByStackIdOrNotFoundError(stackId);
    cluster.getDatabusCredential();
    Telemetry telemetry = componentConfigProviderService.getTelemetry(stackId);
    if (cluster.getDatabusCredential() != null) {
        LOGGER.debug("Databus credential has been found for the stack");
        DataBusCredential dataBusCredential = new Json(cluster.getDatabusCredential()).get(DataBusCredential.class);
        if (isDataBusCredentialStillExist(telemetry, dataBusCredential, stack)) {
            LOGGER.debug("Databus credential exists both in the stack and on UMS side");
            return dataBusCredential;
        } else {
            LOGGER.debug("Databus credential exists on stack side but does not exists on UMS side, it will be updated ...");
        }
    } else {
        LOGGER.debug("Databus credential does not exist for the stack, it will be created ...");
    }
    Optional<AltusCredential> altusCredential = generateDatabusMachineUserForFluent(stack, telemetry, true);
    return storeDataBusCredential(altusCredential, stack);
}
Also used : AltusCredential(com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Json(com.sequenceiq.cloudbreak.common.json.Json) Telemetry(com.sequenceiq.common.api.telemetry.model.Telemetry) DataBusCredential(com.sequenceiq.common.api.telemetry.model.DataBusCredential) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 8 with AltusCredential

use of com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential in project cloudbreak by hortonworks.

the class GrpcUmsClient method generateAccessSecretKeyPair.

/**
 * Generate access / private keypair
 *
 * @param actorCrn       actor that executes the key generation
 * @param machineUserCrn machine user (owner of the access key)
 * @param requestId      id for the request
 * @param accessKeyType  algorithm type used for the access key
 * @return access / private key holder object
 */
@Retryable(value = UmsOperationException.class, maxAttempts = 10, backoff = @Backoff(delay = 5000))
public AltusCredential generateAccessSecretKeyPair(String actorCrn, String accountId, String machineUserCrn, Optional<String> requestId, AccessKeyType.Value accessKeyType, RegionAwareInternalCrnGeneratorFactory regionAwareInternalCrnGeneratorFactory) {
    try {
        UmsClient client = makeClient(channelWrapper.getChannel(), regionAwareInternalCrnGeneratorFactory);
        LOGGER.info("Generating new access / secret key pair for {}", machineUserCrn);
        CreateAccessKeyResponse accessKeyResponse = client.createAccessPrivateKeyPair(RequestIdUtil.getOrGenerate(requestId), actorCrn, accountId, machineUserCrn, accessKeyType);
        return new AltusCredential(accessKeyResponse.getAccessKey().getAccessKeyId(), accessKeyResponse.getPrivateKey().toCharArray());
    } catch (StatusRuntimeException ex) {
        if (Status.UNAVAILABLE.getCode().equals(ex.getStatus().getCode())) {
            String errMessage = String.format("Cannot generate access key pair for machine user '%s' as " + "UMS API is UNAVAILABLE at the moment", machineUserCrn);
            LOGGER.debug(errMessage, ex);
            throw new UmsOperationException(errMessage, ex);
        } else {
            throw ex;
        }
    }
}
Also used : UmsOperationException(com.sequenceiq.cloudbreak.auth.altus.exception.UmsOperationException) AltusCredential(com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential) CreateAccessKeyResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.CreateAccessKeyResponse) StatusRuntimeException(io.grpc.StatusRuntimeException) Retryable(org.springframework.retry.annotation.Retryable)

Example 9 with AltusCredential

use of com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential in project cloudbreak by hortonworks.

the class ClouderaManagerDatabusService method getAltusCredential.

AltusCredential getAltusCredential(Stack stack, String sdxStackCrn) {
    Map<String, String> resourceRoles = calculateResourceRoles(sdxStackCrn);
    AltusCredential credential = createMachineUserAndGenerateKeys(stack, resourceRoles);
    String accessKey = credential.getAccessKey();
    String privateKey = trimAndReplacePrivateKey(credential.getPrivateKey());
    return new AltusCredential(accessKey, privateKey.toCharArray());
}
Also used : AltusCredential(com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential)

Example 10 with AltusCredential

use of com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential in project cloudbreak by hortonworks.

the class AltusMachineUserService method getOrCreateDataBusCredentialIfNeeded.

/**
 * Gather or create DataBus credential for a stack.
 * On creation it will generate aa new workload user with new access/private keys.
 * @param stack stack object that holds details about the cluster
 * @return databus credential holder
 */
public DataBusCredential getOrCreateDataBusCredentialIfNeeded(Stack stack) throws IOException {
    LOGGER.debug("Get or create databus credential for stack");
    Telemetry telemetry = stack.getTelemetry();
    if (stack.getDatabusCredential() != null) {
        LOGGER.debug("Databus credential has been found for the stack");
        DataBusCredential dataBusCredential = new Json(stack.getDatabusCredential()).get(DataBusCredential.class);
        if (isDataBusCredentialStillExist(telemetry, dataBusCredential, stack)) {
            LOGGER.debug("Databus credential exists both in the stack and on UMS side");
            return dataBusCredential;
        } else {
            LOGGER.debug("Databus credential exists on stack side but does not exists on UMS side, it will be updated ...");
        }
    } else {
        LOGGER.debug("Databus credential does not exist for the stack, it will be created ...");
    }
    Optional<AltusCredential> altusCredential = createMachineUserWithAccessKeys(stack, telemetry);
    return storeDataBusCredential(altusCredential, stack);
}
Also used : AltusCredential(com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential) Json(com.sequenceiq.cloudbreak.common.json.Json) Telemetry(com.sequenceiq.common.api.telemetry.model.Telemetry) DataBusCredential(com.sequenceiq.common.api.telemetry.model.DataBusCredential)

Aggregations

AltusCredential (com.sequenceiq.cloudbreak.auth.altus.model.AltusCredential)15 Telemetry (com.sequenceiq.common.api.telemetry.model.Telemetry)4 ApiConfigList (com.cloudera.api.swagger.model.ApiConfigList)3 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)3 DataBusCredential (com.sequenceiq.common.api.telemetry.model.DataBusCredential)3 WorkloadAnalytics (com.sequenceiq.common.api.telemetry.model.WorkloadAnalytics)3 Test (org.junit.Test)3 ClouderaManagerResourceApi (com.cloudera.api.swagger.ClouderaManagerResourceApi)2 ApiRole (com.cloudera.api.swagger.model.ApiRole)2 CreateAccessKeyResponse (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.CreateAccessKeyResponse)2 UmsOperationException (com.sequenceiq.cloudbreak.auth.altus.exception.UmsOperationException)2 ConfigUtils.makeApiConfigList (com.sequenceiq.cloudbreak.cm.util.ConfigUtils.makeApiConfigList)2 Json (com.sequenceiq.cloudbreak.common.json.Json)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 HashMap (java.util.HashMap)2 Retryable (org.springframework.retry.annotation.Retryable)2 ApiClient (com.cloudera.api.swagger.client.ApiClient)1 ApiResponse (com.cloudera.api.swagger.client.ApiResponse)1 ApiRoleList (com.cloudera.api.swagger.model.ApiRoleList)1 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)1