use of io.fabric8.service.ContainerTemplate 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.service.ContainerTemplate in project fabric8 by jboss-fuse.
the class ZooKeeperClusterServiceImpl method publicPort.
private String publicPort(String containerName, final String port) {
FabricService fabric = fabricService.get();
Container container = fabric.getContainer(containerName);
String user = ZooKeeperUtils.getContainerLogin(runtimeProperties.get());
String password = "";
try {
Properties containerTokens = ZooKeeperUtils.getContainerTokens(obtainValid(curator));
password = containerTokens.getProperty(user);
} catch (Exception e) {
LOGGER.error("Unable to get temp ZK user/pass for administrative purposes", e);
}
ContainerTemplate containerTemplate = new ContainerTemplate(container, user, password, false);
return containerTemplate.execute(new JmxTemplateSupport.JmxConnectorCallback<String>() {
@Override
public String doWithJmxConnector(JMXConnector connector) throws Exception {
return connector.getMBeanServerConnection().invoke(new ObjectName("io.fabric8:type=Fabric"), "getPublicPortOnCurrentContainer", new Object[] { new Integer(port) }, new String[] { "int" }).toString();
}
});
}
Aggregations