use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class ContainerRemoveProfileAction method doExecute.
protected Object doExecute() throws Exception {
FabricValidations.validateContainerName(container);
// Do not validate profile names, because we want to be able to remove non-existent profiles.
Container cont = FabricCommand.getContainer(fabricService, container);
// allow to remove non-existing profiles
List<String> profileIds = new ArrayList<>();
for (Profile profile : FabricCommand.getProfiles(fabricService, cont.getVersion(), profiles)) {
profileIds.add(profile.getId());
}
cont.removeProfiles(profileIds.toArray(new String[profileIds.size()]));
return null;
}
use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class ContainerRollbackAction method doExecute.
@Override
protected Object doExecute() throws Exception {
FabricValidations.validateContainerNames(containerIds);
// check and validate version
Version version = profileService.getRequiredVersion(this.version);
if (containerIds == null || containerIds.isEmpty()) {
if (all) {
containerIds = new ArrayList<String>();
for (Container container : fabricService.getContainers()) {
containerIds.add(container.getId());
}
} else {
containerIds = Arrays.asList(fabricService.getCurrentContainer().getId());
}
} else {
if (all) {
throw new IllegalArgumentException("Can not use --all with a list of containers simultaneously");
}
}
List<Container> toRollback = new ArrayList<Container>();
List<Container> same = new ArrayList<Container>();
for (String containerName : containerIds) {
Container container = FabricCommand.getContainer(fabricService, containerName);
// check first that all can rollback
int num = ContainerUpgradeSupport.canRollback(version, container);
if (num < 0) {
throw new IllegalArgumentException("Container " + container.getId() + " has already lower version " + container.getVersion().getId() + " than the requested version " + version.getId() + " to rollback.");
} else if (num == 0) {
// same version
same.add(container);
} else {
// needs rollback
toRollback.add(container);
}
}
// report same version
for (Container container : same) {
System.out.println("Container " + container.getId() + " is already version " + version.getId());
}
// report and do rollbacks
for (Container container : toRollback) {
Version oldVersion = container.getVersion();
// rollback version first
container.setVersion(version);
log.info("Rolled back container {} from {} to {}", new Object[] { container.getId(), oldVersion.getId(), version.getId() });
System.out.println("Rolled back container " + container.getId() + " from version " + oldVersion.getId() + " to " + version.getId());
}
if (all) {
fabricService.setDefaultVersionId(version.getId());
System.out.println("Changed default version to " + version.getId());
}
return null;
}
use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class ContainerUpgradeAction method doExecute.
@Override
protected Object doExecute() throws Exception {
FabricValidations.validateContainerNames(containerIds);
// check and validate version
Version version = profileService.getRequiredVersion(this.version);
if (containerIds == null || containerIds.isEmpty()) {
if (all) {
containerIds = new ArrayList<String>();
for (Container container : fabricService.getContainers()) {
containerIds.add(container.getId());
}
} else {
containerIds = Arrays.asList(fabricService.getCurrentContainer().getId());
}
} else {
if (all) {
throw new IllegalArgumentException("Can not use --all with a list of containers simultaneously");
}
}
List<Container> toUpgrade = new ArrayList<Container>();
List<Container> same = new ArrayList<Container>();
for (String containerName : containerIds) {
Container container = FabricCommand.getContainer(fabricService, containerName);
// check first that all can upgrade
int num = ContainerUpgradeSupport.canUpgrade(version, container);
if (num < 0) {
throw new IllegalArgumentException("Container " + container.getId() + " already has a higher version " + container.getVersion() + " than the requested version " + version.getId() + ".");
} else if (num == 0) {
// same version
same.add(container);
} else {
// needs upgrade
toUpgrade.add(container);
}
}
// report same version
for (Container container : same) {
System.out.println("Container " + container.getId() + " is already at version " + version.getId());
}
// report and do upgrades
for (Container container : toUpgrade) {
Version oldVersion = container.getVersion();
// upgrade version first
container.setVersion(version);
// get the profile for version 1.1
log.info("Upgraded container {} from {} to {}", new Object[] { container.getId(), oldVersion.getId(), version.getId() });
System.out.println("Upgraded container " + container.getId() + " from version " + oldVersion.getId() + " to " + version.getId());
}
if (all) {
fabricService.setDefaultVersionId(version.getId());
System.out.println("Changed default version to " + version.getId());
}
return null;
}
use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class ProfileDynamicJaxbCompiler method recompile.
protected void recompile() {
LOG.debug("Looking for XSDs to recompile");
Set<String> urls = new TreeSet<String>();
FabricService fabric = getFabricService();
Container container = fabric.getCurrentContainer();
String versionId = container.getVersion().getId();
List<String> profileIds = Containers.overlayProfiles(container);
Collection<String> names = listFiles(versionId, profileIds, schemaPath);
for (String name : names) {
if (name.endsWith(".xsd")) {
String prefix = schemaPath;
if (Strings.isNotBlank(prefix)) {
prefix += "/";
}
urls.add("profile:" + prefix + name);
}
}
LOG.info("Recompiling XSDs at URLs: " + urls);
startedFlag.set(false);
ClassLoader classLoader = AriesFrameworkUtil.getClassLoader(bundleContext.getBundle());
if (classLoader == null) {
classLoader = getClass().getClassLoader();
}
DynamicXJC xjc = new DynamicXJC(classLoader);
xjc.setSchemaUrls(new ArrayList<String>(urls));
compileResults = xjc.compileSchemas();
if (handler != null) {
handler.onCompileResults(compileResults);
}
if (introspector != null) {
introspector.setClassLoaderProvider("dynamic.jaxb", new ClassLoaderProvider() {
@Override
public ClassLoader getClassLoader() {
return compileResults.getClassLoader();
}
});
}
}
use of io.fabric8.api.FabricService in project fabric8 by jboss-fuse.
the class FabricServiceImpl method substituteConfigurations.
/**
* Performs substitution to configuration based on the registered {@link PlaceholderResolver} instances.
*/
public Map<String, Map<String, String>> substituteConfigurations(final Map<String, Map<String, String>> configurations) {
final Map<String, PlaceholderResolver> resolversSnapshot = new HashMap<String, PlaceholderResolver>(placeholderResolvers);
// Check that all resolvers are available
Set<String> requiredSchemes = getSchemesForProfileConfigurations(configurations);
Set<String> availableSchemes = resolversSnapshot.keySet();
if (!availableSchemes.containsAll(requiredSchemes)) {
StringBuilder sb = new StringBuilder();
sb.append("Missing Placeholder Resolvers:");
for (String scheme : requiredSchemes) {
if (!availableSchemes.contains(scheme)) {
sb.append(" ").append(scheme);
}
}
throw new FabricException(sb.toString());
}
final Map<String, Map<String, String>> mutableConfigurations = new HashMap<>();
for (Entry<String, Map<String, String>> entry : configurations.entrySet()) {
String key = entry.getKey();
Map<String, String> value = new HashMap<>(entry.getValue());
mutableConfigurations.put(key, value);
}
final FabricService fabricService = this;
for (Map.Entry<String, Map<String, String>> entry : mutableConfigurations.entrySet()) {
final String pid = entry.getKey();
Map<String, String> props = entry.getValue();
Map<String, String> original = new HashMap<>(props);
for (Map.Entry<String, String> e : original.entrySet()) {
final String key = e.getKey();
final String value = e.getValue();
try {
props.put(key, InterpolationHelper.substVars(value, key, null, props, new InterpolationHelper.SubstitutionCallback() {
public String getValue(String toSubstitute) {
if (toSubstitute != null && toSubstitute.contains(":")) {
String scheme = toSubstitute.substring(0, toSubstitute.indexOf(":"));
return resolversSnapshot.get(scheme).resolve(fabricService, mutableConfigurations, pid, key, toSubstitute);
}
return substituteBundleProperty(toSubstitute, bundleContext);
}
}));
} catch (EncryptionOperationNotPossibleException exception) {
LOGGER.warn("Error resolving " + key, exception);
}
}
}
return mutableConfigurations;
}
Aggregations