Search in sources :

Example 1 with PluginConfigurationException

use of alien4cloud.paas.exception.PluginConfigurationException in project alien4cloud by alien4cloud.

the class OrchestratorStateService method load.

/**
 * Load and connect the given orchestrator.
 *
 * @param orchestrator the orchestrator to load and connect.
 */
private void load(Orchestrator orchestrator) throws PluginConfigurationException {
    log.info("Loading and connecting orchestrator {} (id: {})", orchestrator.getName(), orchestrator.getId());
    // check that the orchestrator is not already loaded.
    if (orchestratorPluginService.get(orchestrator.getId()) != null) {
        throw new AlreadyExistException("Plugin is already loaded.");
    }
    // switch the state to connecting
    orchestrator.setState(OrchestratorState.CONNECTING);
    alienDAO.save(orchestrator);
    // TODO move below in a thread to perform plugin loading and connection asynchronously
    IOrchestratorPluginFactory orchestratorFactory = orchestratorService.getPluginFactory(orchestrator);
    IOrchestratorPlugin<Object> orchestratorInstance = orchestratorFactory.newInstance();
    // Set the configuration for the provider
    OrchestratorConfiguration orchestratorConfiguration = orchestratorConfigurationService.getConfigurationOrFail(orchestrator.getId());
    try {
        Object configuration = orchestratorConfigurationService.configurationAsValidObject(orchestrator.getId(), orchestratorConfiguration.getConfiguration());
        orchestratorInstance.setConfiguration(orchestrator.getId(), configuration);
    } catch (IOException e) {
        throw new PluginConfigurationException("Failed convert configuration json in object.", e);
    }
    // index the archive in alien catalog
    archiveIndexer.indexOrchestratorArchives(orchestratorFactory, orchestratorInstance);
    // connect the orchestrator
    orchestratorInstance.init(deploymentService.getCloudActiveDeploymentContexts(orchestrator.getId()));
    // register the orchestrator instance to be polled for updates
    orchestratorPluginService.register(orchestrator.getId(), orchestratorInstance);
    orchestrator.setState(OrchestratorState.CONNECTED);
    alienDAO.save(orchestrator);
    if (orchestratorInstance instanceof ILocationAutoConfigurer) {
        // trigger locations auto-configurations
        locationService.autoConfigure(orchestrator, (ILocationAutoConfigurer) orchestratorInstance);
    }
    indexLocationsArchives(orchestrator);
}
Also used : IOrchestratorPluginFactory(alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory) ILocationAutoConfigurer(alien4cloud.orchestrators.plugin.ILocationAutoConfigurer) IOException(java.io.IOException) PluginConfigurationException(alien4cloud.paas.exception.PluginConfigurationException) AlreadyExistException(alien4cloud.exception.AlreadyExistException) OrchestratorConfiguration(alien4cloud.model.orchestrators.OrchestratorConfiguration)

Example 2 with PluginConfigurationException

use of alien4cloud.paas.exception.PluginConfigurationException in project yorc-a4c-plugin by ystia.

the class RestClient method setProviderConfiguration.

public void setProviderConfiguration(ProviderConfig providerConfiguration) throws PluginConfigurationException {
    this.providerConfiguration = providerConfiguration;
    log.debug("setProviderConfiguration YorcURL=" + providerConfiguration.getUrlYorc());
    try {
        getDeployments();
    } catch (UnirestException e) {
        log.warn("Cannot access Yorc: " + e.getCause());
        throw new PluginConfigurationException("Cannot access Yorc: " + e.getCause());
    }
    if (Boolean.TRUE.equals(providerConfiguration.getInsecureTLS())) {
        SSLContext sslContext;
        try {
            sslContext = SSLContexts.custom().loadTrustMaterial(null, (chain, authType) -> true).build();
        } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
            e.printStackTrace();
            throw new PluginConfigurationException("Failed to create SSL socket factory", e);
        }
        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
        RequestConfig clientConfig = RequestConfig.custom().setConnectTimeout(((Long) CONNECTION_TIMEOUT).intValue()).setSocketTimeout(((Long) SOCKET_TIMEOUT).intValue()).setConnectionRequestTimeout(((Long) SOCKET_TIMEOUT).intValue()).build();
        CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(clientConfig).setSSLSocketFactory(sslsf).build();
        Unirest.setHttpClient(httpClient);
    }
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) UnirestException(com.mashape.unirest.http.exceptions.UnirestException) PluginConfigurationException(alien4cloud.paas.exception.PluginConfigurationException) SSLContext(javax.net.ssl.SSLContext) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) KeyManagementException(java.security.KeyManagementException)

Aggregations

PluginConfigurationException (alien4cloud.paas.exception.PluginConfigurationException)2 AlreadyExistException (alien4cloud.exception.AlreadyExistException)1 OrchestratorConfiguration (alien4cloud.model.orchestrators.OrchestratorConfiguration)1 ILocationAutoConfigurer (alien4cloud.orchestrators.plugin.ILocationAutoConfigurer)1 IOrchestratorPluginFactory (alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory)1 UnirestException (com.mashape.unirest.http.exceptions.UnirestException)1 IOException (java.io.IOException)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SSLContext (javax.net.ssl.SSLContext)1 RequestConfig (org.apache.http.client.config.RequestConfig)1 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1