Search in sources :

Example 1 with IEnvironmentVariable

use of com.openshift.client.IEnvironmentVariable in project camel by apache.

the class OpenShiftProducer method doGetEnvironmentVariableValue.

protected void doGetEnvironmentVariableValue(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 variableName = exchange.getIn().getHeader(OpenShiftConstants.ENVIRONMENT_VARIABLE_NAME, getEndpoint().getApplication(), String.class);
        if (!app.canGetEnvironmentVariables()) {
            throw new CamelExchangeException("The application with id " + name + " can't get Environment Variables", exchange);
        }
        if (ObjectHelper.isNotEmpty(variableName)) {
            IEnvironmentVariable result = app.getEnvironmentVariable(variableName);
            exchange.getIn().setBody(result.getValue());
        } else {
            throw new CamelExchangeException("Environment variable name not specified", exchange);
        }
    }
}
Also used : CamelExchangeException(org.apache.camel.CamelExchangeException) IApplication(com.openshift.client.IApplication) IEnvironmentVariable(com.openshift.client.IEnvironmentVariable)

Example 2 with IEnvironmentVariable

use of com.openshift.client.IEnvironmentVariable in project camel by apache.

the class OpenShiftProducer method doAddMultipleEnvironmentVariables.

protected void doAddMultipleEnvironmentVariables(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 {
        Map environmentVariables = exchange.getIn().getHeader(OpenShiftConstants.ENVIRONMENT_VARIABLE_MAP, getEndpoint().getApplication(), Map.class);
        if (!app.canUpdateEnvironmentVariables()) {
            throw new CamelExchangeException("The application with id " + name + " can't update Environment Variables", exchange);
        }
        if (ObjectHelper.isNotEmpty(environmentVariables)) {
            Map<String, IEnvironmentVariable> result = app.addEnvironmentVariables(environmentVariables);
            exchange.getIn().setBody(result);
        } else {
            throw new CamelExchangeException("Environment variables not correctly specified", exchange);
        }
    }
}
Also used : CamelExchangeException(org.apache.camel.CamelExchangeException) IApplication(com.openshift.client.IApplication) IEnvironmentVariable(com.openshift.client.IEnvironmentVariable) Map(java.util.Map)

Example 3 with IEnvironmentVariable

use of com.openshift.client.IEnvironmentVariable in project camel by apache.

the class OpenShiftProducer method doAddEnvironmentVariable.

protected void doAddEnvironmentVariable(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 variableName = exchange.getIn().getHeader(OpenShiftConstants.ENVIRONMENT_VARIABLE_NAME, getEndpoint().getApplication(), String.class);
        String variableValue = exchange.getIn().getHeader(OpenShiftConstants.ENVIRONMENT_VARIABLE_VALUE, getEndpoint().getApplication(), String.class);
        if (!app.canUpdateEnvironmentVariables()) {
            throw new CamelExchangeException("The application with id " + name + " can't update Environment Variables", exchange);
        }
        if (ObjectHelper.isNotEmpty(variableName) && ObjectHelper.isNotEmpty(variableValue)) {
            IEnvironmentVariable result = app.addEnvironmentVariable(variableName, variableValue);
            exchange.getIn().setBody(result.getName());
        } else {
            throw new CamelExchangeException("Environment variable not correctly specified", exchange);
        }
    }
}
Also used : CamelExchangeException(org.apache.camel.CamelExchangeException) IApplication(com.openshift.client.IApplication) IEnvironmentVariable(com.openshift.client.IEnvironmentVariable)

Example 4 with IEnvironmentVariable

use of com.openshift.client.IEnvironmentVariable in project camel by apache.

the class OpenShiftProducer method doUpdateEnvironmentVariable.

protected void doUpdateEnvironmentVariable(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 variableName = exchange.getIn().getHeader(OpenShiftConstants.ENVIRONMENT_VARIABLE_NAME, getEndpoint().getApplication(), String.class);
        String variableValue = exchange.getIn().getHeader(OpenShiftConstants.ENVIRONMENT_VARIABLE_VALUE, getEndpoint().getApplication(), String.class);
        if (!app.canUpdateEnvironmentVariables()) {
            throw new CamelExchangeException("The application with id " + name + " can't update Environment Variables", exchange);
        }
        if (ObjectHelper.isNotEmpty(variableName) && ObjectHelper.isNotEmpty(variableValue)) {
            IEnvironmentVariable result = app.updateEnvironmentVariable(variableName, variableValue);
            exchange.getIn().setBody(result.getName());
        } else {
            throw new CamelExchangeException("Environment variable not correctly specified", exchange);
        }
    }
}
Also used : CamelExchangeException(org.apache.camel.CamelExchangeException) IApplication(com.openshift.client.IApplication) IEnvironmentVariable(com.openshift.client.IEnvironmentVariable)

Example 5 with IEnvironmentVariable

use of com.openshift.client.IEnvironmentVariable in project camel by apache.

the class OpenShiftProducer method doGetAllEnvironmentVariables.

protected void doGetAllEnvironmentVariables(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 {
        Map<String, IEnvironmentVariable> result = app.getEnvironmentVariables();
        exchange.getIn().setBody(result);
    }
}
Also used : CamelExchangeException(org.apache.camel.CamelExchangeException) IApplication(com.openshift.client.IApplication) IEnvironmentVariable(com.openshift.client.IEnvironmentVariable)

Aggregations

IApplication (com.openshift.client.IApplication)5 IEnvironmentVariable (com.openshift.client.IEnvironmentVariable)5 CamelExchangeException (org.apache.camel.CamelExchangeException)5 Map (java.util.Map)1