use of io.fabric8.api.FabricException in project fabric8 by jboss-fuse.
the class OpenshiftContainerProvider method getContainerApplication.
private IApplication getContainerApplication(Container container, boolean required) {
IApplication app = null;
CreateOpenshiftContainerMetadata metadata = OpenShiftUtils.getContainerMetadata(container);
if (metadata != null) {
IOpenShiftConnection connection = getOrCreateConnection(metadata.getCreateOptions());
app = OpenShiftUtils.getApplication(container, metadata, connection);
}
if (app == null && required) {
throw new FabricException("Unable to find OpenShift application for " + container.getId());
}
return app;
}
use of io.fabric8.api.FabricException in project fabric8 by jboss-fuse.
the class ClusterBootstrapManager method getCreateEnsembleOptions.
static CreateEnsembleOptions getCreateEnsembleOptions(RuntimeProperties sysprops, Map<String, Object> options) {
String username = (String) options.remove("username");
String password = (String) options.remove("password");
String role = (String) options.remove("role");
if (username == null || password == null || role == null) {
throw new FabricException("Must specify an administrator username, password and administrative role when creating a fabric");
}
Object profileObject = options.remove("profiles");
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
CreateEnsembleOptions.Builder builder = mapper.convertValue(options, CreateEnsembleOptions.Builder.class);
if (profileObject != null) {
List profiles = mapper.convertValue(profileObject, List.class);
builder.profiles(profiles);
}
org.apache.felix.utils.properties.Properties userProps = null;
try {
userProps = new org.apache.felix.utils.properties.Properties(sysprops.getConfPath().resolve("users.properties").toFile());
} catch (IOException e) {
userProps = new org.apache.felix.utils.properties.Properties();
}
if (userProps.get(username) == null) {
userProps.put(username, password + "," + role);
}
CreateEnsembleOptions answer = builder.users(userProps).withUser(username, password, role).build();
LOG.debug("Creating ensemble with options: {}", answer);
System.setProperty(ZkDefs.GLOBAL_RESOLVER_PROPERTY, answer.getGlobalResolver());
System.setProperty(ZkDefs.LOCAL_RESOLVER_PROPERTY, answer.getResolver());
System.setProperty(ZkDefs.MANUAL_IP, answer.getManualIp());
System.setProperty(ZkDefs.BIND_ADDRESS, answer.getBindAddress());
System.setProperty(ZkDefs.MINIMUM_PORT, "" + answer.getMinimumPort());
System.setProperty(ZkDefs.MAXIMUM_PORT, "" + answer.getMaximumPort());
return answer;
}
use of io.fabric8.api.FabricException in project fabric8 by jboss-fuse.
the class FabricManager method applyPatches.
@Override
public void applyPatches(List<String> files, String sourceId, String targetId, String proxyUser, String proxyPassword) {
List<File> patchFiles = new ArrayList<File>();
for (String fileName : files) {
File file = new File(fileName);
if (file.exists()) {
patchFiles.add(file);
} else {
LOG.warn("Patch file does not exist, skipping: {}", fileName);
}
}
if (patchFiles.isEmpty()) {
LOG.warn("No valid patches to apply");
throw new FabricException("No valid patches to apply");
}
if (targetId == null || targetId.equals("")) {
Version latestVersion = getLatestVersion();
VersionSequence sequence = new VersionSequence(latestVersion.getId());
targetId = sequence.next().getName();
}
Version targetVersion = profileService.createVersionFrom(sourceId, targetId, null);
File currentPatchFile = null;
try {
for (File file : patchFiles) {
currentPatchFile = file;
if (!file.isFile()) {
LOG.info("File is a directory, skipping: {}", file);
continue;
}
LOG.info("Applying patch file {}", file);
fabricService.getPatchService().applyPatch(targetVersion, file.toURI().toURL(), proxyUser, proxyPassword);
LOG.info("Successfully applied {}", file);
}
} catch (Throwable t) {
LOG.warn("Failed to apply patch file {}", currentPatchFile, t);
profileService.deleteVersion(targetId);
throw new FabricException("Failed to apply patch file " + currentPatchFile, t);
}
for (File file : patchFiles) {
try {
LOG.info("Deleting patch file {}", file);
boolean deleted = file.delete();
if (!deleted) {
LOG.warn("Failed to delete patch file {}", file);
}
} catch (Throwable t) {
LOG.warn("Failed to delete patch file {} due to {}", file, t);
}
}
}
use of io.fabric8.api.FabricException in project fabric8 by jboss-fuse.
the class FabricManager method deleteConfigurationFiles.
@Override
public void deleteConfigurationFiles(String versionId, List<String> profileIds, List<String> fileNames) {
if (profileIds.size() != fileNames.size()) {
throw new FabricException("Lists of profile IDs and filenames should be the same size");
}
for (int i = 0; i < profileIds.size(); i++) {
String profileId = profileIds.get(i);
String fileName = fileNames.get(i);
Profile profile = profileService.getRequiredProfile(versionId, profileId);
ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile);
builder.deleteFileConfiguration(fileName);
profileService.updateProfile(builder.getProfile());
}
}
use of io.fabric8.api.FabricException in project fabric8 by jboss-fuse.
the class CreateContainerTask method call.
@Override
public Set<ContainerProxy> call() throws Exception {
Set<ContainerProxy> containers = new HashSet<ContainerProxy>();
FabricService fabricService = fabricServiceProxy.getService();
CreateContainerMetadata[] allMetadata = fabricService.createContainers(options);
if (allMetadata != null && allMetadata.length > 0) {
for (CreateContainerMetadata metadata : allMetadata) {
Container container = metadata.getContainer();
containers.add(ContainerProxy.wrap(container, fabricServiceProxy));
if (!metadata.isSuccess()) {
throw new FabricException("Failed to create container.", metadata.getFailure());
}
}
}
return containers;
}
Aggregations