Search in sources :

Example 1 with IGearGroup

use of com.openshift.client.IGearGroup 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)1 IGear (com.openshift.client.IGear)1 IGearGroup (com.openshift.client.IGearGroup)1 IEmbeddedCartridge (com.openshift.client.cartridge.IEmbeddedCartridge)1 SimpleDateFormat (java.text.SimpleDateFormat)1