use of io.fabric8.api.CreateChildContainerOptions in project fabric8 by jboss-fuse.
the class ChildContainerProvider method createKarafContainerController.
private ChildContainerController createKarafContainerController() {
return new ChildContainerController() {
@Override
public CreateChildContainerMetadata create(final CreateChildContainerOptions options, final CreationStateListener listener) {
final Container parent = fabricService.get().getContainer(options.getParent());
ContainerTemplate containerTemplate = new ContainerTemplate(parent, options.getJmxUser(), options.getJmxPassword(), false);
return containerTemplate.execute(new ContainerTemplate.AdminServiceCallback<CreateChildContainerMetadata>() {
public CreateChildContainerMetadata doWithAdminService(AdminServiceMBean adminService) throws Exception {
return doCreateKaraf(adminService, options, listener, parent);
}
});
}
@Override
public void start(final Container container) {
getContainerTemplateForChild(container).execute(new ContainerTemplate.AdminServiceCallback<Object>() {
public Object doWithAdminService(AdminServiceMBean adminService) throws Exception {
// update jvm options if they have have changed
CreateChildContainerMetadata metadata = (CreateChildContainerMetadata) container.getMetadata();
CreateChildContainerOptions createOptions = metadata.getCreateOptions();
String jvmOpts = createOptions.getJvmOpts();
TabularData instances = adminService.getInstances();
Collection<CompositeDataSupport> values = (Collection<CompositeDataSupport>) instances.values();
for (CompositeDataSupport o : values) {
if (container.getId().equals(o.get("Name"))) {
if (o.containsKey("JavaOpts")) {
String oldJavaOpts = (String) o.get("JavaOpts");
StringBuilder stringBuilder = ChildContainerProvider.buildJvmOpts(createOptions, fabricService.get());
String extendendJvmOpts = stringBuilder.toString();
if (jvmOpts != null && !extendendJvmOpts.equals(oldJavaOpts)) {
adminService.changeJavaOpts(container.getId(), extendendJvmOpts);
}
}
break;
}
}
adminService.startInstance(container.getId(), null);
return null;
}
});
}
@Override
public void stop(final Container container) {
getContainerTemplateForChild(container).execute(new ContainerTemplate.AdminServiceCallback<Object>() {
public Object doWithAdminService(AdminServiceMBean adminService) throws Exception {
String prevProvisionResult = container.getProvisionResult();
container.setProvisionResult(Container.PROVISION_STOPPING);
try {
adminService.stopInstance(container.getId());
container.setProvisionResult(Container.PROVISION_STOPPED);
} catch (Throwable t) {
container.setProvisionResult(prevProvisionResult);
LOG.error("Failed to stop container: " + container.getId(), t);
throw t;
}
return null;
}
});
}
@Override
public void destroy(final Container container) {
getContainerTemplateForChild(container).execute(new ContainerTemplate.AdminServiceCallback<Object>() {
public Object doWithAdminService(AdminServiceMBean adminService) throws Exception {
adminService.destroyInstance(container.getId());
return null;
}
});
}
};
}
use of io.fabric8.api.CreateChildContainerOptions in project fabric8 by jboss-fuse.
the class ChildAutoScaler method createContainers.
@Override
public void createContainers(AutoScaleRequest request) throws Exception {
int count = request.getDelta();
String profile = request.getProfile();
String version = request.getVersion();
FabricService fabricService = request.getFabricService();
CreateChildContainerOptions.Builder builder = null;
if (fabricService != null) {
builder = createAutoScaleOptions(request, fabricService);
}
if (builder != null) {
Set<String> ignoreContainerNames = new HashSet<>();
for (int i = 0; i < count; i++) {
final CreateChildContainerOptions.Builder configuredBuilder = builder.number(1).version(version).profiles(profile);
Container[] containers = fabricService.getContainers();
NameValidator nameValidator = Containers.createNameValidator(containers);
String name = Containers.createAutoScaleContainerName(containers, profile, containerProvider.getScheme(), nameValidator);
ignoreContainerNames.add(name);
CreateChildContainerOptions options = configuredBuilder.name(name).build();
LOG.info("Creating container name " + name + " version " + version + " profile " + profile + " " + count + " container(s)");
fabricService.createContainers(options);
}
} else {
LOG.warn("Could not create version " + version + " profile " + profile + " due to missing autoscale configuration");
}
}
Aggregations