use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class SubnetChooserService method chooseSubnets.
public List<CloudSubnet> chooseSubnets(List<CloudSubnet> subnetMetas, CloudPlatform cloudPlatform, DBStack dbStack) {
NetworkConnector networkConnector = cloudPlatformConnectors.get(new CloudPlatformVariant(dbStack.getCloudPlatform(), dbStack.getPlatformVariant())).networkConnector();
SubnetSelectionParameters build = SubnetSelectionParameters.builder().withHa(dbStack.isHa()).withPreferPrivateIfExist().build();
SubnetSelectionResult subnetSelectionResult = networkConnector.chooseSubnets(subnetMetas, build);
if (subnetSelectionResult.hasError()) {
throw new BadRequestException(subnetSelectionResult.getErrorMessage());
}
return subnetSelectionResult.getResult();
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class ClusterCommonServiceTest method testRotateAutoTlsCertificatesWithNodeFailure.
@Test
public void testRotateAutoTlsCertificatesWithNodeFailure() {
NameOrCrn cluster = NameOrCrn.ofName("cluster");
Stack stack = new Stack();
stack.setName("cluster");
stack.setStackStatus(new StackStatus(stack, NODE_FAILURE));
when(stackService.getByNameOrCrnInWorkspace(cluster, 1L)).thenReturn(stack);
CertificatesRotationV4Request certificatesRotationV4Request = new CertificatesRotationV4Request();
BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> underTest.rotateAutoTlsCertificates(cluster, 1L, certificatesRotationV4Request));
assertEquals("Stack 'cluster' is currently in 'NODE_FAILURE' state. Certificates rotation can only be made when the underlying stack is 'AVAILABLE'.", badRequestException.getMessage());
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class HostKeytabService method generateHostKeytab.
public HostKeytabResponse generateHostKeytab(HostKeytabRequest request, String accountId) throws FreeIpaClientException {
LOGGER.debug("Request to generate host keytab: {}", request);
Stack freeIpaStack = keytabCommonService.getFreeIpaStackWithMdcContext(request.getEnvironmentCrn(), accountId);
FreeIpaClient ipaClient = freeIpaClientFactory.getFreeIpaClientForStack(freeIpaStack);
if (!roleComponent.privilegesExist(request.getRoleRequest(), ipaClient)) {
throw new BadRequestException(PRIVILEGE_DOES_NOT_EXIST);
} else {
Host host = keytabCommonService.addHost(request.getServerHostName(), request.getRoleRequest(), ipaClient);
KeytabCache hostKeytab = fetchKeytab(request, ipaClient, host);
return createHostKeytabResponse(hostKeytab);
}
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class HostKeytabService method getExistingHostKeytab.
public HostKeytabResponse getExistingHostKeytab(HostKeytabRequest request, String accountId) throws FreeIpaClientException {
LOGGER.debug("Request to get host keytab for account {}: {}", accountId, request);
if (request.getRoleRequest() != null) {
throw new BadRequestException(ROLE_NOT_ALLOWED);
} else {
Stack freeIpaStack = keytabCommonService.getFreeIpaStackWithMdcContext(request.getEnvironmentCrn(), accountId);
FreeIpaClient ipaClient = freeIpaClientFactory.getFreeIpaClientForStack(freeIpaStack);
String hostPrincipal = ipaClient.showHost(request.getServerHostName()).getKrbprincipalname();
KeytabCache hostKeytab = keytabCommonService.getExistingKeytab(request.getEnvironmentCrn(), hostPrincipal, request.getServerHostName(), ipaClient);
return createHostKeytabResponse(hostKeytab);
}
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class LdapConfigValidator method validateLdapConnection.
private void validateLdapConnection(String protocol, String serverHost, Integer serverPort, String bindDn, String bindPassword) {
try {
LOGGER.debug("Validate connection to LDAP host: '{}', port: '{}', protocol: '{}'.", serverHost, serverPort, protocol);
// BEGIN GENERATED CODE
Hashtable<String, String> env = new Hashtable<>();
// END GENERATED CODE
env.put("com.sun.jndi.ldap.read.timeout", "1000");
env.put("com.sun.jndi.ldap.connect.timeout", "5000");
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
String url = new StringBuilder(protocol).append("://").append(serverHost).append(':').append(serverPort).toString();
env.put(Context.PROVIDER_URL, url);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, bindDn);
env.put(Context.SECURITY_CREDENTIALS, bindPassword);
Context ctx = new InitialDirContext(env);
ctx.close();
} catch (NamingException e) {
throw new BadRequestException("Failed to connect to LDAP server: " + e.getMessage(), e);
}
}
Aggregations