use of com.openshift.client.cartridge.EmbeddableCartridge in project fabric8 by jboss-fuse.
the class OpenshiftContainerProvider method create.
@Override
public CreateOpenshiftContainerMetadata create(CreateOpenshiftContainerOptions options, CreationStateListener listener) throws Exception {
assertValid();
IUser user = getOrCreateConnection(options).getUser();
IDomain domain = getOrCreateDomain(user, options);
String cartridgeUrl = null;
Set<String> profiles = options.getProfiles();
String versionId = options.getVersion();
Map<String, String> openshiftConfigOverlay = new HashMap<String, String>();
if (profiles != null && versionId != null) {
ProfileService profileService = fabricService.get().adapt(ProfileService.class);
Version version = profileService.getVersion(versionId);
if (version != null) {
for (String profileId : profiles) {
Profile profile = version.getRequiredProfile(profileId);
if (profile != null) {
Profile overlay = profileService.getOverlayProfile(profile);
Map<String, String> openshiftConfig = overlay.getConfiguration(OpenShiftConstants.OPENSHIFT_PID);
if (openshiftConfig != null) {
openshiftConfigOverlay.putAll(openshiftConfig);
}
}
}
}
cartridgeUrl = openshiftConfigOverlay.get("cartridge");
}
if (cartridgeUrl == null) {
cartridgeUrl = defaultCartridgeUrl;
}
String[] cartridgeUrls = cartridgeUrl.split(" ");
LOG.info("Creating cartridges: " + cartridgeUrl);
String standAloneCartridgeUrl = cartridgeUrls[0];
StandaloneCartridge cartridge;
if (standAloneCartridgeUrl.startsWith(PREFIX_CARTRIDGE_ID)) {
cartridge = new StandaloneCartridge(standAloneCartridgeUrl.substring(PREFIX_CARTRIDGE_ID.length()));
} else {
cartridge = new StandaloneCartridge(new URL(standAloneCartridgeUrl));
}
String zookeeperUrl = fabricService.get().getZookeeperUrl();
String zookeeperPassword = fabricService.get().getZookeeperPassword();
Map<String, String> userEnvVars = null;
if (!options.isEnsembleServer()) {
userEnvVars = new HashMap<String, String>();
userEnvVars.put("OPENSHIFT_FUSE_ZOOKEEPER_URL", zookeeperUrl);
userEnvVars.put("OPENSHIFT_FUSE_ZOOKEEPER_PASSWORD", zookeeperPassword);
String zkPasswordEncode = System.getProperty("zookeeper.password.encode", "true");
userEnvVars.put("OPENSHIFT_FUSE_ZOOKEEPER_PASSWORD_ENCODE", zkPasswordEncode);
userEnvVars.put("OPENSHIFT_FUSE_CREATED_FROM_FABRIC", "true");
}
String initGitUrl = null;
int timeout = IHttpClient.NO_TIMEOUT;
ApplicationScale scale = null;
String containerName = options.getName();
long t0 = System.currentTimeMillis();
IApplication application;
try {
application = domain.createApplication(containerName, cartridge, scale, new GearProfile(options.getGearProfile()), initGitUrl, timeout, userEnvVars);
} catch (OpenShiftTimeoutException e) {
long t1;
do {
Thread.sleep(5000);
domain.refresh();
application = domain.getApplicationByName(containerName);
if (application != null) {
break;
}
t1 = System.currentTimeMillis();
} while (t1 - t0 < TimeUnit.MILLISECONDS.convert(15, TimeUnit.MINUTES));
}
LOG.info("Created application " + containerName);
// now lets add all the embedded cartridges
List<IEmbeddableCartridge> list = new ArrayList<IEmbeddableCartridge>();
for (int idx = 1, size = cartridgeUrls.length; idx < size; idx++) {
String embeddedUrl = cartridgeUrls[idx];
LOG.info("Adding embedded cartridge: " + embeddedUrl);
if (embeddedUrl.startsWith(PREFIX_CARTRIDGE_ID)) {
list.add(new EmbeddableCartridge(embeddedUrl.substring(PREFIX_CARTRIDGE_ID.length())));
} else {
list.add(new EmbeddableCartridge(new URL(embeddedUrl)));
}
}
if (!list.isEmpty()) {
application.addEmbeddableCartridges(list);
}
String gitUrl = application.getGitUrl();
// in case of OpenShiftTimeoutException, application resource doesn't contain getCreationLog().
// actually this method throws NPE
CreateOpenshiftContainerMetadata metadata = new CreateOpenshiftContainerMetadata(domain.getId(), application.getUUID(), application.getMessages() == null ? "" : application.getCreationLog(), gitUrl);
metadata.setContainerName(containerName);
metadata.setCreateOptions(options);
return metadata;
}
Aggregations