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");
}
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);
}
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;
}
}
}
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());
}
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);
}
Aggregations