use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class ManagedCartridgeConfig method loadConfig.
/**
* Loads the managed cartridge configuration for the given containerId
*/
public static ManagedCartridgeConfig loadConfig(FabricService fabricService, String containerId) throws IOException {
String propertiesText = fabricService.adapt(DataStore.class).getContainerAttribute(containerId, DataStore.ContainerAttribute.OpenShift, "", false, substitutedStringValue);
if (propertiesText == null) {
return null;
}
Properties properties = new Properties();
properties.load(new StringReader(propertiesText));
ManagedCartridgeConfig answer = new ManagedCartridgeConfig(properties);
LOG.info("Loaded managed cartridge configuration " + answer);
return answer;
}
use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class ManagedCartridgeConfig method saveConfig.
/**
* Saves the managed cartridge configuration data
*/
public static ManagedCartridgeConfig saveConfig(FabricService fabricService, String containerId, CreateOpenshiftContainerOptions options, IApplication application) throws IOException {
ManagedCartridgeConfig config = new ManagedCartridgeConfig();
config.setServerUrl(options.getServerUrl());
config.setLogin(options.getLogin());
config.setPassword(options.getPassword());
StringWriter writer = new StringWriter();
config.getProperties().store(writer, "Saved by " + config.getClass() + " at " + new Date());
String propertiesText = writer.toString();
LOG.info("Saved managed cartridge configuration: " + propertiesText);
fabricService.adapt(DataStore.class).setContainerAttribute(containerId, DataStore.ContainerAttribute.OpenShift, propertiesText);
return config;
}
use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class DeploymentUpdater method updateDeployment.
public void updateDeployment(Git git, File baseDir, CredentialsProvider credentials) throws Exception {
Set<String> bundles = new LinkedHashSet<String>();
Set<Feature> features = new LinkedHashSet<Feature>();
Profile overlayProfile = container.getOverlayProfile();
Profile effectiveProfile = Profiles.getEffectiveProfile(fabricService, overlayProfile);
bundles.addAll(effectiveProfile.getBundles());
AgentUtils.addFeatures(features, fabricService, downloadManager, effectiveProfile);
if (copyFilesIntoGit) {
copyDeploymentsIntoGit(git, baseDir, bundles, features);
} else {
addDeploymentsIntoPom(git, baseDir, effectiveProfile, bundles, features);
}
// now lets do a commit
String message = "updating deployment";
git.commit().setMessage(message).call();
enableDeployDirectory(git, baseDir);
String branch = GitHelpers.currentBranch(git);
LOG.info("Pushing deployment changes to branch " + branch + " credentials " + credentials + " for container " + container.getId());
try {
Iterable<PushResult> results = git.push().setCredentialsProvider(credentials).setRefSpecs(new RefSpec(branch)).setOutputStream(new LoggingOutputStream(LOG)).call();
/*
for (PushResult result : results) {
LOG.info(result.getMessages());
}
*/
LOG.info("Pushed deployment changes to branch " + branch + " for container " + container.getId());
} catch (GitAPIException e) {
LOG.error("Failed to push deployment changes to branch " + branch + " for container " + container.getId() + ". Reason: " + e, e);
}
}
use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class OpenShiftDeployAgent method createDeployTask.
private DeploymentUpdater createDeployTask(Container container, Map<String, String> openshiftConfiguration) throws MalformedURLException {
String webappDir = relativePath(container, openshiftConfiguration, OpenShiftConstants.PROPERTY_DEPLOY_WEBAPPS);
String deployDir = relativePath(container, openshiftConfiguration, OpenShiftConstants.PROPERTY_DEPLOY_JARS);
if (webappDir != null || deployDir != null) {
FabricService fabric = fabricService.get();
DownloadManager downloadManager = DownloadManagers.createDownloadManager(fabric, downloadExecutor);
DeploymentUpdater deploymentUpdater = new DeploymentUpdater(downloadManager, fabric, container, webappDir, deployDir);
deploymentUpdater.setRepositories(Maps.stringValue(openshiftConfiguration, OpenShiftConstants.PROPERTY_REPOSITORIES, OpenShiftConstants.DEFAULT_REPOSITORIES));
deploymentUpdater.setCopyFilesIntoGit(Maps.booleanValue(openshiftConfiguration, OpenShiftConstants.PROPERTY_COPY_BINARIES_TO_GIT, false));
return deploymentUpdater;
}
return null;
}
use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class MQCreateAction method doExecute.
@Override
protected Object doExecute() throws Exception {
MQBrokerConfigDTO dto = createDTO();
Profile profile = MQManager.createOrUpdateProfile(dto, fabricService, runtimeProperties);
if (profile == null) {
return null;
}
String profileId = profile.getId();
System.out.println("MQ profile " + profileId + " ready");
// assign profile to existing containers
if (assign != null) {
String[] assignContainers = assign.split(",");
MQManager.assignProfileToContainers(fabricService, profile, assignContainers);
}
// create containers
if (create != null) {
String[] createContainers = create.split(",");
List<CreateContainerBasicOptions.Builder> builderList = MQManager.createContainerBuilders(dto, fabricService, "child", profileId, dto.version(), createContainers);
for (CreateContainerBasicOptions.Builder builder : builderList) {
CreateContainerMetadata[] metadatas;
try {
if (builder instanceof CreateChildContainerOptions.Builder) {
CreateChildContainerOptions.Builder childBuilder = (CreateChildContainerOptions.Builder) builder;
builder = childBuilder.jmxUser(username).jmxPassword(password);
}
metadatas = fabricService.createContainers(builder.build());
// check if there was a FabricAuthenticationException as failure then we can try again
if (metadatas != null) {
for (CreateContainerMetadata meta : metadatas) {
if (meta.getFailure() != null && meta.getFailure() instanceof FabricAuthenticationException) {
throw (FabricAuthenticationException) meta.getFailure();
}
}
}
ShellUtils.storeFabricCredentials(session, username, password);
} catch (FabricAuthenticationException fae) {
// If authentication fails, prompts for credentials and try again.
if (builder instanceof CreateChildContainerOptions.Builder) {
CreateChildContainerOptions.Builder childBuilder = (CreateChildContainerOptions.Builder) builder;
promptForJmxCredentialsIfNeeded();
metadatas = fabricService.createContainers(childBuilder.jmxUser(username).jmxPassword(password).build());
ShellUtils.storeFabricCredentials(session, username, password);
}
}
}
}
return null;
}
Aggregations