Search in sources :

Example 51 with CamelExchangeException

use of org.apache.camel.CamelExchangeException in project camel by apache.

the class OpenShiftProducer method doScaleUp.

protected void doScaleUp(Exchange exchange, IDomain domain) throws CamelExchangeException {
    String name = exchange.getIn().getHeader(OpenShiftConstants.APPLICATION, getEndpoint().getApplication(), String.class);
    if (name == null) {
        throw new CamelExchangeException("Application not specified", exchange);
    }
    IApplication app = domain.getApplicationByName(name);
    if (app == null) {
        throw new CamelExchangeException("Application with id " + name + " not found.", exchange);
    } else {
        try {
            app.scaleUp();
            ApplicationScale result = app.getApplicationScale();
            exchange.getIn().setBody(result.getValue());
        } catch (OpenShiftException e) {
            throw new CamelExchangeException("Application with id " + name + " is not scalable", exchange);
        }
    }
}
Also used : CamelExchangeException(org.apache.camel.CamelExchangeException) IApplication(com.openshift.client.IApplication) ApplicationScale(com.openshift.client.ApplicationScale) OpenShiftException(com.openshift.client.OpenShiftException)

Example 52 with CamelExchangeException

use of org.apache.camel.CamelExchangeException in project camel by apache.

the class OpenShiftProducer method doAddAlias.

protected void doAddAlias(Exchange exchange, IDomain domain) throws CamelExchangeException {
    String name = exchange.getIn().getHeader(OpenShiftConstants.APPLICATION, getEndpoint().getApplication(), String.class);
    if (name == null) {
        throw new CamelExchangeException("Application not specified", exchange);
    }
    IApplication app = domain.getApplicationByName(name);
    if (app == null) {
        throw new CamelExchangeException("Application with id " + name + " not found.", exchange);
    } else {
        String alias = exchange.getIn().getHeader(OpenShiftConstants.APPLICATION_ALIAS, getEndpoint().getApplication(), String.class);
        if (!app.canGetEnvironmentVariables()) {
            throw new CamelExchangeException("The application with id " + name + " can't get Environment Variables", exchange);
        }
        if (ObjectHelper.isNotEmpty(alias)) {
            app.addAlias(alias);
            exchange.getIn().setBody(alias);
        } else {
            throw new CamelExchangeException("Application Alias name not specified", exchange);
        }
    }
}
Also used : CamelExchangeException(org.apache.camel.CamelExchangeException) IApplication(com.openshift.client.IApplication)

Example 53 with CamelExchangeException

use of org.apache.camel.CamelExchangeException in project camel by apache.

the class OpenShiftProducer method doAddEmbeddedCartridge.

protected void doAddEmbeddedCartridge(Exchange exchange, IDomain domain) throws CamelExchangeException {
    String name = exchange.getIn().getHeader(OpenShiftConstants.APPLICATION, getEndpoint().getApplication(), String.class);
    if (name == null) {
        throw new CamelExchangeException("Application not specified", exchange);
    }
    IApplication app = domain.getApplicationByName(name);
    if (app == null) {
        throw new CamelExchangeException("Application with id " + name + " not found.", exchange);
    } else {
        String embeddedCartridgeName = exchange.getIn().getHeader(OpenShiftConstants.EMBEDDED_CARTRIDGE_NAME, getEndpoint().getApplication(), String.class);
        if (ObjectHelper.isNotEmpty(embeddedCartridgeName)) {
            IEmbeddedCartridge p = app.addEmbeddableCartridge((new LatestEmbeddableCartridge(embeddedCartridgeName)).get(app));
            exchange.getIn().setBody(p.getDisplayName());
        } else {
            throw new CamelExchangeException("Cartridge not specified", exchange);
        }
    }
}
Also used : CamelExchangeException(org.apache.camel.CamelExchangeException) IApplication(com.openshift.client.IApplication) LatestEmbeddableCartridge(com.openshift.client.cartridge.query.LatestEmbeddableCartridge) IEmbeddedCartridge(com.openshift.client.cartridge.IEmbeddedCartridge)

Example 54 with CamelExchangeException

use of org.apache.camel.CamelExchangeException in project camel by apache.

the class OpenShiftProducer method process.

@Override
public void process(Exchange exchange) throws Exception {
    String openshiftServer = OpenShiftHelper.getOpenShiftServer(getEndpoint());
    IDomain domain = OpenShiftHelper.loginAndGetDomain(getEndpoint(), openshiftServer);
    if (domain == null) {
        throw new CamelExchangeException("User has no domain with id " + getEndpoint().getDomain(), exchange);
    }
    OpenShiftOperation operation = exchange.getIn().getHeader(OpenShiftConstants.OPERATION, getEndpoint().getOperation(), OpenShiftOperation.class);
    switch(operation) {
        case start:
            doStart(exchange, domain);
            break;
        case stop:
            doStop(exchange, domain);
            break;
        case restart:
            doRestart(exchange, domain);
            break;
        case state:
            doState(exchange, domain);
            break;
        case getStandaloneCartridge:
            doGetStandaloneCartridge(exchange, domain);
            break;
        case getEmbeddedCartridges:
            doGetEmbeddedCartridges(exchange, domain);
            break;
        case getGitUrl:
            doGetGitUrl(exchange, domain);
            break;
        case addEmbeddedCartridge:
            doAddEmbeddedCartridge(exchange, domain);
            break;
        case removeEmbeddedCartridge:
            doRemoveEmbeddedCartridge(exchange, domain);
            break;
        case scaleUp:
            doScaleUp(exchange, domain);
            break;
        case scaleDown:
            doScaleDown(exchange, domain);
            break;
        case getDeploymentType:
            doGetDeploymentType(exchange, domain);
            break;
        case setDeploymentType:
            doSetDeploymentType(exchange, domain);
            break;
        case addEnvironmentVariable:
            doAddEnvironmentVariable(exchange, domain);
            break;
        case addMultipleEnvironmentVariables:
            doAddMultipleEnvironmentVariables(exchange, domain);
            break;
        case updateEnvironmentVariable:
            doUpdateEnvironmentVariable(exchange, domain);
            break;
        case getAllEnvironmentVariables:
            doGetAllEnvironmentVariables(exchange, domain);
            break;
        case getEnvironmentVariableValue:
            doGetEnvironmentVariableValue(exchange, domain);
            break;
        case removeEnvironmentVariable:
            doRemoveEnvironmentVariable(exchange, domain);
            break;
        case getGearProfile:
            doGetGearProfile(exchange, domain);
            break;
        case addAlias:
            doAddAlias(exchange, domain);
            break;
        case removeAlias:
            doRemoveAlias(exchange, domain);
            break;
        case getAliases:
            doGetAliases(exchange, domain);
            break;
        case list:
        default:
            // and do list by default
            if (getEndpoint().getMode().equals("json")) {
                doListJson(exchange, domain);
            } else {
                doListPojo(exchange, domain);
            }
            break;
    }
}
Also used : CamelExchangeException(org.apache.camel.CamelExchangeException) IDomain(com.openshift.client.IDomain)

Example 55 with CamelExchangeException

use of org.apache.camel.CamelExchangeException in project camel by apache.

the class OpenShiftProducer method doStop.

protected void doStop(Exchange exchange, IDomain domain) throws CamelExchangeException {
    String name = exchange.getIn().getHeader(OpenShiftConstants.APPLICATION, getEndpoint().getApplication(), String.class);
    if (name == null) {
        throw new CamelExchangeException("Application not specified", exchange);
    }
    IApplication app = domain.getApplicationByName(name);
    if (app == null) {
        throw new CamelExchangeException("Application with id " + name + " not found.", exchange);
    } else {
        app.stop();
    }
}
Also used : CamelExchangeException(org.apache.camel.CamelExchangeException) IApplication(com.openshift.client.IApplication)

Aggregations

CamelExchangeException (org.apache.camel.CamelExchangeException)82 IApplication (com.openshift.client.IApplication)23 Exchange (org.apache.camel.Exchange)17 IOException (java.io.IOException)10 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)8 IEnvironmentVariable (com.openshift.client.IEnvironmentVariable)5 InputStream (java.io.InputStream)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 AsyncCallback (org.apache.camel.AsyncCallback)5 CamelExecutionException (org.apache.camel.CamelExecutionException)5 Message (org.apache.camel.Message)5 File (java.io.File)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Processor (org.apache.camel.Processor)4 RouteBuilder (org.apache.camel.builder.RouteBuilder)4 IEmbeddedCartridge (com.openshift.client.cartridge.IEmbeddedCartridge)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Serializable (java.io.Serializable)3 URI (java.net.URI)3 List (java.util.List)3