use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class StackCreatorServiceRecipeValidationTest method testIfRecipeExistsThenEverythingShouldBeFine.
@Test
void testIfRecipeExistsThenEverythingShouldBeFine() throws TransactionExecutionException {
String existingRecipeName = "existingRecipe";
StackV4Request request = new StackV4Request();
request.setName("stack_name");
request.setInstanceGroups(List.of(getInstanceGroupWithRecipe(INSTANCE_GROUP_MASTER, Set.of(existingRecipeName))));
when(recipeService.get(any(NameOrCrn.class), eq(WORKSPACE_ID))).thenReturn(getRecipeWithName(existingRecipeName));
when(stackV4RequestToStackConverter.convert(request)).thenReturn(TestUtil.stack());
when(transactionService.required(any(Supplier.class))).thenReturn(TestUtil.stack());
when(stackService.getIdByNameInWorkspace(anyString(), any(Long.class))).thenThrow(new NotFoundException("stack not found by name"));
underTest.createStack(user, workspace, request, false);
verify(recipeService, times(1)).get(any(NameOrCrn.class), anyLong());
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class StackCreatorServiceRecipeValidationTest method voidTestIfRecipeDoesNotExistInInstanceGroupV4RequestThenEverythingShouldGoFine.
@Test
void voidTestIfRecipeDoesNotExistInInstanceGroupV4RequestThenEverythingShouldGoFine() throws TransactionExecutionException {
StackV4Request request = new StackV4Request();
request.setName("stack_name");
request.setInstanceGroups(List.of(getInstanceGroupWithRecipe(INSTANCE_GROUP_MASTER, null), getInstanceGroupWithRecipe(INSTANCE_GROUP_COMPUTE, null)));
when(stackV4RequestToStackConverter.convert(request)).thenReturn(TestUtil.stack());
when(transactionService.required(any(Supplier.class))).thenReturn(TestUtil.stack());
when(stackService.getIdByNameInWorkspace(anyString(), any(Long.class))).thenThrow(new NotFoundException("stack not found by name"));
underTest.createStack(user, workspace, request, false);
verify(recipeService, times(0)).get(any(NameOrCrn.class), anyLong());
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class ClusterHostServiceRunner method createKnoxRelatedGatewayCofniguration.
private Map<String, Object> createKnoxRelatedGatewayCofniguration(Cluster cluster, VirtualGroupRequest virtualGroupRequest, ClusterPreCreationApi connector) throws IOException {
Gateway clusterGateway = cluster.getGateway();
Map<String, Object> gateway = new HashMap<>();
if (clusterGateway != null) {
gateway.put("path", clusterGateway.getPath());
gateway.put("ssotype", clusterGateway.getSsoType());
gateway.put("ssoprovider", clusterGateway.getSsoProvider());
gateway.put("signpub", clusterGateway.getSignPub());
gateway.put("signcert", clusterGateway.getSignCert());
gateway.put("signkey", clusterGateway.getSignKey());
gateway.put("tokencert", clusterGateway.getTokenCert());
gateway.put("mastersecret", clusterGateway.getKnoxMasterSecret());
gateway.put("envAccessGroup", virtualGroupService.createOrGetVirtualGroup(virtualGroupRequest, UmsVirtualGroupRight.ENVIRONMENT_ACCESS));
List<Map<String, Object>> topologies = getTopologies(clusterGateway, cluster.getBlueprint().getStackVersion());
gateway.put("topologies", topologies);
if (cluster.getBlueprint() != null) {
Boolean autoTlsEnabled = cluster.getAutoTlsEnabled();
Map<String, Integer> servicePorts = connector.getServicePorts(cluster.getBlueprint(), autoTlsEnabled);
gateway.put("ports", servicePorts);
gateway.put("protocol", autoTlsEnabled ? "https" : "http");
}
if (SSOType.SSO_PROVIDER_FROM_UMS.equals(clusterGateway.getSsoType())) {
String accountId = ThreadBasedUserCrnProvider.getAccountId();
try {
String metadataXml = umsClient.getIdentityProviderMetadataXml(accountId, regionAwareInternalCrnGeneratorFactory);
gateway.put("saml", metadataXml);
} catch (Exception e) {
LOGGER.debug("Could not get SAML metadata file to set up IdP in KNOXSSO.", e);
throw new NotFoundException("Could not get SAML metadata file to set up IdP in KNOXSSO: " + e.getMessage());
}
}
} else {
gateway.put("ssotype", SSOType.NONE);
LOGGER.debug("Cluster gateway (Knox) is not set. Configure ssotype to 'NONE' for backward compatibility.");
}
return gateway;
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class StackImageService method changeImageCatalog.
public void changeImageCatalog(Stack stack, String imageCatalog) {
try {
Image currentImage = componentConfigProviderService.getImage(stack.getId());
ImageCatalog targetImageCatalog = imageCatalogService.getImageCatalogByName(stack.getWorkspace().getId(), imageCatalog);
StatedImage targetImage = imageCatalogService.getImage(targetImageCatalog.getImageCatalogUrl(), targetImageCatalog.getName(), currentImage.getImageId());
replaceStackImageComponent(stack, targetImage);
} catch (IllegalArgumentException e) {
LOGGER.error("Failed to change the image catalog.", e);
throw new CloudbreakServiceException("Failed to change the image catalog.");
} catch (CloudbreakImageNotFoundException e) {
LOGGER.error(e.getMessage(), e);
throw new NotFoundException(e.getMessage());
} catch (CloudbreakImageCatalogException e) {
LOGGER.error("Failed to replace stack image component", e);
throw new CloudbreakServiceException(e.getMessage());
}
}
use of com.sequenceiq.cloudbreak.common.exception.NotFoundException in project cloudbreak by hortonworks.
the class StackService method getByCrnInWorkspaceWithEntries.
public StackV4Response getByCrnInWorkspaceWithEntries(String crn, Long workspaceId, Set<String> entries, User user, StackType stackType) {
try {
return transactionService.required(() -> {
Workspace workspace = workspaceService.get(workspaceId, user);
ShowTerminatedClustersAfterConfig showTerminatedClustersAfterConfig = showTerminatedClusterConfigService.get();
Optional<Stack> stack = findByCrnAndWorkspaceIdWithLists(crn, workspace.getId(), stackType, showTerminatedClustersAfterConfig);
if (stack.isEmpty()) {
throw new NotFoundException(format("Stack not found by crn '%s'", crn));
}
StackV4Response stackResponse = stackToStackV4ResponseConverter.convert(stack.get());
stackResponse = stackResponseDecorator.decorate(stackResponse, stack.get(), entries);
return stackResponse;
});
} catch (TransactionExecutionException e) {
throw new TransactionRuntimeExecutionException(e);
}
}
Aggregations