Search in sources :

Example 16 with IApplication

use of com.openshift.client.IApplication 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 17 with IApplication

use of com.openshift.client.IApplication 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 18 with IApplication

use of com.openshift.client.IApplication 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 19 with IApplication

use of com.openshift.client.IApplication 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 20 with IApplication

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

the class OpenShiftProducer method doListJson.

protected void doListJson(Exchange exchange, IDomain domain) {
    StringBuilder sb = new StringBuilder("{\n  \"applications\": [");
    boolean first = true;
    for (IApplication application : domain.getApplications()) {
        if (!first) {
            sb.append("\n    ],");
        } else {
            first = false;
        }
        String date = new SimpleDateFormat(TIMESTAMP_FORMAT).format(application.getCreationTime());
        // application
        sb.append("\n    {");
        sb.append("\n      \"uuid\": \"" + application.getUUID() + "\",");
        sb.append("\n      \"domain\": \"" + application.getDomain().getId() + "\",");
        sb.append("\n      \"name\": \"" + application.getName() + "\",");
        sb.append("\n      \"creationTime\": \"" + date + "\",");
        sb.append("\n      \"applicationUrl\": \"" + application.getApplicationUrl() + "\",");
        sb.append("\n      \"gitUrl\": \"" + application.getGitUrl() + "\",");
        sb.append("\n      \"sshUrl\": \"" + application.getSshUrl() + "\",");
        // catridge
        sb.append("\n      \"catridge\": {");
        sb.append("\n        \"name\": \"" + application.getCartridge().getName() + "\",");
        sb.append("\n        \"displayName\": \"" + application.getCartridge().getDisplayName() + "\",");
        sb.append("\n        \"description\": \"" + application.getCartridge().getDescription() + "\"");
        sb.append("\n      },");
        // embedded catridges
        List<IEmbeddedCartridge> embeddedCartridges = application.getEmbeddedCartridges();
        if (embeddedCartridges != null && !embeddedCartridges.isEmpty()) {
            sb.append("\n      \"embeddedCatridges\": [");
            for (Iterator<IEmbeddedCartridge> it = embeddedCartridges.iterator(); it.hasNext(); ) {
                IEmbeddedCartridge cartridge = it.next();
                sb.append("\n      \"catridge\": {");
                sb.append("\n        \"name\": \"" + cartridge.getName() + "\",");
                sb.append("\n        \"displayName\": \"" + cartridge.getDisplayName() + "\",");
                sb.append("\n        \"description\": \"" + cartridge.getDescription() + "\"");
                sb.append("\n      }");
                if (it.hasNext()) {
                    sb.append(",");
                }
            }
            sb.append("\n      ]");
        }
        sb.append("\n      \"gearProfile\": \"" + application.getGearProfile().getName() + "\",");
        sb.append("\n      \"gears\": [");
        boolean firstGear = true;
        for (IGearGroup group : application.getGearGroups()) {
            for (IGear gear : group.getGears()) {
                if (!firstGear) {
                    sb.append(",");
                } else {
                    firstGear = false;
                }
                sb.append("\n        {");
                sb.append("\n         \"id\": \"" + gear.getId() + "\",");
                sb.append("\n         \"sshUrl\": \"" + gear.getSshUrl() + "\",");
                sb.append("\n         \"state\": \"" + gear.getState().getState().toLowerCase(Locale.ENGLISH) + "\"");
                sb.append("\n        }");
            }
        }
        sb.append("\n      ]");
        sb.append("\n    }");
    }
    sb.append("\n  ]");
    sb.append("\n}");
    exchange.getIn().setBody(sb.toString());
}
Also used : IApplication(com.openshift.client.IApplication) IGearGroup(com.openshift.client.IGearGroup) SimpleDateFormat(java.text.SimpleDateFormat) IEmbeddedCartridge(com.openshift.client.cartridge.IEmbeddedCartridge) IGear(com.openshift.client.IGear)

Aggregations

IApplication (com.openshift.client.IApplication)25 CamelExchangeException (org.apache.camel.CamelExchangeException)23 IEnvironmentVariable (com.openshift.client.IEnvironmentVariable)5 IEmbeddedCartridge (com.openshift.client.cartridge.IEmbeddedCartridge)4 ApplicationScale (com.openshift.client.ApplicationScale)2 LatestEmbeddableCartridge (com.openshift.client.cartridge.query.LatestEmbeddableCartridge)2 IGear (com.openshift.client.IGear)1 IGearGroup (com.openshift.client.IGearGroup)1 IGearProfile (com.openshift.client.IGearProfile)1 OpenShiftException (com.openshift.client.OpenShiftException)1 IDeployedStandaloneCartridge (com.openshift.client.cartridge.IDeployedStandaloneCartridge)1 IEmbeddableCartridge (com.openshift.client.cartridge.IEmbeddableCartridge)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Endpoint (org.apache.camel.Endpoint)1 Exchange (org.apache.camel.Exchange)1