Refine search
private boolean containerExists(String containerName) { Container[] containers = fabricService.getContainers(); for (Container c : containers) { if (containerName.equals(c.getId())) { return true; } } return false; } }
/** * Does the container match the given version. * <p/> * If the version is <tt>null</tt> then the container matches. * * @param container the container * @param version the version * @return <tt>true</tt> if matches */ public static boolean matchVersion(Container container, Version version) { if (version == null) { // always match if no version in filter return true; } return version.equals(container.getVersion()); }
/** * Returns true if the given container has the given profile directly (rather than inheritence) */ public static boolean containerHasProfile(Container container, String profileId) { for (Profile p : container.getProfiles()) { if (profileId.equals(p.getId())) { return true; } } return false; }
private boolean isComplete(Container container, String status) { return container.isAlive() && (container.getProvisionStatus().equals(status) || !container.isManaged()) && container.getSshUrl() != null; } }
/** * Returns true if the container is a live and provisioned successfully. */ public static boolean isAliveAndProvisionSuccess(Container container) { if (container == null) { return false; } boolean alive = container.isAlive(); boolean provisioningPending = container.isProvisioningPending(); String provisionResult = container.getProvisionResult(); return alive && !provisioningPending && Container.PROVISION_SUCCESS.equals(provisionResult); }
System.out.println(String.format(FORMAT, "Name:", container.getId())); System.out.println(String.format(FORMAT, "Version:", container.getVersionId())); System.out.println(String.format(FORMAT, "Connected:", container.isAlive())); System.out.println(String.format(FORMAT, "Type:", emptyIfNull(container.getType()))); System.out.println(String.format(FORMAT, "Root:", container.isRoot())); System.out.println(String.format(FORMAT, "Ensemble Server:", container.isEnsembleServer())); System.out.println(String.format(FORMAT, "Managed:", container.isManaged())); Long processId = container.getProcessId(); System.out.println(String.format(FORMAT, "Process ID:", ((processId != null) ? processId.toString() : ""))); if (Strings.isNotBlank(container.getLocation())) { System.out.println(String.format(FORMAT, "Location:", emptyIfNull(container.getLocation()))); System.out.println(String.format(FORMAT, "Resolver:", emptyIfNull(container.getResolver()))); System.out.println(String.format(FORMAT, "Network Address:", emptyIfNull(container.getIp()))); System.out.println(String.format(FORMAT, "Local Network Address:", emptyIfNull(container.getLocalIp()))); System.out.println(String.format(FORMAT, "Public Network Address:", emptyIfNull(container.getPublicIp()))); System.out.println(String.format(FORMAT, "Local Hostname:", emptyIfNull(container.getLocalHostname()))); System.out.println(String.format(FORMAT, "Public Hostname:", emptyIfNull(container.getPublicHostname()))); System.out.println(String.format(FORMAT, "SSH Url:", emptyIfNull(container.getSshUrl()))); System.out.println(String.format(FORMAT, "JMX Url:", emptyIfNull(container.getJmxUrl()))); System.out.println(String.format(FORMAT, "Http Url:", emptyIfNull(container.getHttpUrl()))); System.out.println(String.format(FORMAT, "Jolokia Url:", emptyIfNull(container.getJolokiaUrl()))); String debugPort = container.getDebugPort(); if (Strings.isNotBlank(debugPort)) { System.out.println(String.format(FORMAT, "Debug Port:", debugPort)); Profile[] profiles = container.getProfiles(); for (int i = 0; i < profiles.length; i++) {
private static String substituteFromProfile(FabricService fabricService, Map<String, Map<String, String>> configs, String pid, String key) { Map<String, String> configuration = configs.get(pid); if (configuration != null && configuration.containsKey(key)) { return configuration.get(key); } else { // lets default to the current container if a version doesn't exist in a different profile Profile overlayProfile = fabricService.getCurrentContainer().getOverlayProfile(); Profile effectiveProfile = Profiles.getEffectiveProfile(fabricService, overlayProfile); configuration = effectiveProfile.getConfiguration(pid); if (configuration != null && configuration.containsKey(key)) { return configuration.get(key); } else { return EMPTY; } } }
@Override public String toString() { return "Container[" + "id=" + id + (parent != null ? ", parent=" + parent.getId() : "") + ']'; }
/** * Creates an aggregation of all available {@link Profile}s. */ private Profile getAllProfilesOverlay() { Container container = fabricService.get().getCurrentContainer(); ProfileService profileService = fabricService.get().adapt(ProfileService.class); Version version = container.getVersion(); Profile versionProfile = getVersionProfile(version); return Profiles.getEffectiveProfile(fabricService.get(), profileService.getOverlayProfile(versionProfile)); }
@Override public void start(Container container) { CreateContainerMetadata metadata = container.getMetadata(); if (!(metadata instanceof CreateSshContainerMetadata)) { throw new IllegalStateException("Container doesn't have valid create container metadata type"); } else { CreateSshContainerMetadata sshContainerMetadata = (CreateSshContainerMetadata) metadata; CreateSshContainerOptions options = sshContainerMetadata.getCreateOptions(); Session session = null; try { String script = buildStartScript(container.getId(), options); session = createSession(options); runScriptOnHost(session, script); } catch (Throwable t) { LOGGER.error("Failed to start container: " + container.getId(), t); } finally { if (session != null) { session.disconnect(); } } } }
@Override public Boolean call() throws Exception { for (long t = 0; (!isComplete(container, status) && t < provisionTimeOut); t += 2000L) { if (container.getProvisionException() != null) { return false; } Thread.sleep(2000L); System.out.println("Container:" + container.getId() + " Alive:" + container.isAlive() + " Status:" + container.getProvisionStatus() + " SSH URL:" + container.getSshUrl()); } if (!isComplete(container, status)) { return false; } return true; }
public Container[] getChildren() { List<Container> children = new ArrayList<Container>(); for (Container container : fabricService.getContainers()) { if (container.getParent() != null && getId().equals(container.getParent().getId())) { children.add(container); } } return children.toArray(new Container[children.size()]); }
String currentContainersVersionId = fabricService.getCurrentContainer().getVersionId(); if (!simulation && versionId.equals(currentContainersVersionId)) { throw new UnsupportedOperationException("Can't install Rollup patch in current version. Please install" + fabricService.adapt(ProfileService.class).getRequiredVersion(versionId); patchManagement.uploadPatchArtifacts(patch.getPatchData(), fabricService.getMavenRepoUploadURI(), callback);
public static void renameProfile(FabricService fabricService, String versionId, String sourceId, String targetId, boolean force) { ProfileService profileService = fabricService.adapt(ProfileService.class); Profile sourceProfile = profileService.getRequiredProfile(versionId, sourceId); LOGGER.info("renameProfile: {} => {}", sourceProfile, targetId); // [TODO] delete/create profile must be done in an atomic operation maybeDeleteProfile(fabricService, versionId, targetId, force); ProfileBuilder builder = ProfileBuilder.Factory.createFrom(sourceProfile); Profile targetProfile = profileService.createProfile(builder.identity(targetId).getProfile()); // TODO: what about child profiles ? for (Container container : fabricService.getAssociatedContainers(versionId, sourceId)) { Profile[] containerProfiles = container.getProfiles(); Set<Profile> profileSet = new HashSet<Profile>(Arrays.asList(containerProfiles)); profileSet.remove(sourceProfile); profileSet.add(targetProfile); container.setProfiles(profileSet.toArray(new Profile[profileSet.size()])); } maybeDeleteProfile(fabricService, versionId, sourceId, true); }
protected void onConfigurationChanged() { LOGGER.info("Configuration has changed; so checking the Fabric managed Java cartridges on OpenShift are up to date"); Container[] containers = fabricService.get().getContainers(); for (Container container : containers) { Profile effectiveProfile = Profiles.getEffectiveProfile(fabricService.get(), container.getOverlayProfile()); Map<String, String> openshiftConfiguration = effectiveProfile.getConfiguration(OpenShiftConstants.OPENSHIFT_PID); if (openshiftConfiguration != null) { String containerId = container.getId(); IOpenShiftConnection connection = OpenShiftUtils.createConnection(container); CreateOpenshiftContainerOptions options = OpenShiftUtils.getCreateOptions(container);
@Override public void deleteVersion(String versionId) { Container[] containers = fabricService.getContainers(); StringBuilder sb = new StringBuilder(); for (Container container : fabricService.getContainers()) { if (versionId.equals(container.getVersionId())) { if (sb.length() > 0) { sb.append(", "); } sb.append(container.getId()); } } IllegalStateAssertion.assertTrue(sb.length() == 0, "Version " + versionId + " is still used by the following containers: " + sb.toString()); profileService.deleteVersion(versionId); }
@Override public void stop(Container container) { CreateContainerMetadata metadata = container.getMetadata(); if (!(metadata instanceof CreateSshContainerMetadata)) { throw new IllegalStateException("Container doesn't have valid create container metadata type"); } else { CreateSshContainerMetadata sshContainerMetadata = (CreateSshContainerMetadata) metadata; CreateSshContainerOptions options = sshContainerMetadata.getCreateOptions(); Session session = null; try { String script = buildStopScript(container.getId(), options); session = createSession(options); runScriptOnHost(session, script); container.setProvisionResult(Container.PROVISION_STOPPED); } catch (Throwable t) { LOGGER.error("Failed to stop container: " + container.getId(), t); } finally { if (session != null) { session.disconnect(); } } } }
Container container = null; if (containerId != null) { container = fabricService.get().getContainer(containerId); } else { container = fabricService.get().getCurrentContainer(); Profile overlayProfile = container.getOverlayProfile(); bytes = overlayProfile.getFileConfiguration(path); resolved = true;