use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class GatewayTopologyToGatewayTopologyV4ResponseConverterTest method testConvertWithNoServicesAndException.
@Test
public void testConvertWithNoServicesAndException() throws IOException {
GatewayTopology source = mock(GatewayTopology.class);
when(source.getTopologyName()).thenReturn(TOPOLOGY);
Json json = mock(Json.class);
when(source.getExposedServices()).thenReturn(json);
when(json.getValue()).thenReturn("{}");
when(json.get(ExposedServices.class)).thenThrow(new IOException("Foo"));
GatewayTopologyV4Response result = underTest.convert(source);
assertNotNull(result);
assertEquals(TOPOLOGY, result.getTopologyName());
assertNull(result.getExposedServices());
}
use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class GatewayTopologyToGatewayTopologyV4ResponseConverterTest method testConvertWithSomeServices.
@Test
public void testConvertWithSomeServices() throws IOException {
GatewayTopology source = mock(GatewayTopology.class);
when(source.getTopologyName()).thenReturn(TOPOLOGY);
ExposedServices exposedServices = mock(ExposedServices.class);
List<String> services = List.of("SERVICE1", "SERVICE2");
when(exposedServices.getServices()).thenReturn(services);
Json json = mock(Json.class);
when(source.getExposedServices()).thenReturn(json);
when(json.getValue()).thenReturn("{}");
when(json.get(ExposedServices.class)).thenReturn(exposedServices);
GatewayTopologyV4Response result = underTest.convert(source);
assertNotNull(result);
assertEquals(TOPOLOGY, result.getTopologyName());
assertEquals(services, result.getExposedServices());
}
use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class InteractiveCredentialCreationStatusHandler method accept.
@Override
public void accept(Event<InteractiveCredentialCreationStatus> interactiveCredentialCreationStatusEvent) {
InteractiveCredentialCreationStatus interactiveCredentialCreationStatus = interactiveCredentialCreationStatusEvent.getData();
String userCrn = interactiveCredentialCreationStatus.getExtendedCloudCredential().getUserCrn();
ThreadBasedUserCrnProvider.doAs(userCrn, () -> {
String message = interactiveCredentialCreationStatus.getMessage();
InteractiveCredentialNotification notification = new InteractiveCredentialNotification().withEventTimestamp(new Date().getTime()).withUserId(interactiveCredentialCreationStatus.getExtendedCloudCredential().getUserCrn()).withCloud(interactiveCredentialCreationStatus.getExtendedCloudCredential().getCloudPlatform()).withEventMessage(message);
ResourceEvent event;
if (interactiveCredentialCreationStatus.isError()) {
event = CREDENTIAL_AZURE_INTERACTIVE_FAILED;
notification.withEventType(event.name());
LOGGER.info("Interactive credential creation failed status: {}", new Json(notification).getValue());
} else {
event = CREDENTIAL_AZURE_INTERACTIVE_STATUS;
notification.withEventType(event.name());
LOGGER.info("Interactive credential creation success status: {}", new Json(notification).getValue());
}
notificationService.send(event, notification, ThreadBasedUserCrnProvider.getUserCrn());
});
}
use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class CredentialService method updateAuthorizationCodeOfAzureCredential.
private void updateAuthorizationCodeOfAzureCredential(Credential credential, String authorizationCode) {
try {
CredentialAttributes credentialAttributes = new Json(credential.getAttributes()).get(CredentialAttributes.class);
if (credentialAttributes.getAzure() != null && credentialAttributes.getAzure().getCodeGrantFlowBased() != null) {
CodeGrantFlowAttributes codeGrantFlowAttributes = credentialAttributes.getAzure().getCodeGrantFlowBased();
codeGrantFlowAttributes.setAuthorizationCode(authorizationCode);
credential.setAttributes(new Json(credentialAttributes).getValue());
}
} catch (IOException e) {
LOGGER.info("Attributes of credential '{}' could not get from JSON attributes", credential.getName());
}
}
use of com.sequenceiq.cloudbreak.common.json.Json in project cloudbreak by hortonworks.
the class CredentialService method create.
public Credential create(Credential credential, @Nonnull String accountId, @Nonnull String creatorUserCrn, CredentialType type) {
repository.findByNameAndAccountId(credential.getName(), accountId, getEnabledPlatforms(), type).map(Credential::getName).ifPresent(name -> {
throw new BadRequestException("Credential already exists with name: " + name);
});
LOGGER.debug("Validating credential for cloudPlatform {} and creator {}.", credential.getCloudPlatform(), creatorUserCrn);
credentialValidator.validateCredentialCloudPlatform(credential.getCloudPlatform(), creatorUserCrn, type);
LOGGER.debug("Validating credential parameters for cloudPlatform {} and creator {}.", credential.getCloudPlatform(), creatorUserCrn);
credentialValidator.validateParameters(Platform.platform(credential.getCloudPlatform()), new Json(credential.getAttributes()));
String credentialCrn = createCRN(accountId);
credential.setResourceCrn(credentialCrn);
credential.setCreator(creatorUserCrn);
credential.setAccountId(accountId);
Credential verifiedCredential = credentialAdapter.verify(credential, accountId, Boolean.TRUE).getCredential();
if (verifiedCredential.getVerificationStatusText() != null) {
throw new BadRequestException(verifiedCredential.getVerificationStatusText());
}
try {
Credential createdCredential = transactionService.required(() -> {
Credential created = repository.save(verifiedCredential);
ownerAssignmentService.assignResourceOwnerRoleIfEntitled(creatorUserCrn, credentialCrn, accountId);
return created;
});
sendCredentialNotification(createdCredential, ResourceEvent.CREDENTIAL_CREATED);
return createdCredential;
} catch (TransactionService.TransactionExecutionException e) {
LOGGER.error("Error happened during credential creation: ", e);
throw new InternalServerErrorException(e);
}
}
Aggregations