use of io.fabric8.api.Container in project fabric8 by jboss-fuse.
the class ContainerResource method delete.
/**
* Deletes this container
*/
@DELETE
public void delete() {
FabricService fabricService = getFabricService();
Objects.notNull(fabricService, "fabricService");
fabricService.destroyContainer(container);
}
use of io.fabric8.api.Container in project fabric8 by jboss-fuse.
the class FabricDTO method createContainerDTO.
public static ContainerDTO createContainerDTO(Container container, String baseApiLink) {
ContainerDTO answer = new ContainerDTO();
String containerId = container.getId();
answer.setId(containerId);
answer.setType(container.getType());
answer.setChildren(Containers.containerIds(container.getChildren()));
List<String> profileIds = Profiles.profileIds(container.getProfiles());
String profileLinkPrefix = baseApiLink + "/version/" + Profiles.versionId(container.getVersion()) + "/profile/";
answer.setProfiles(Links.mapIdsToLinks(profileIds, profileLinkPrefix));
answer.setVersion(Profiles.versionId(container.getVersion()));
answer.setParent(Containers.containerId(container.getParent()));
answer.setIp(container.getIp());
answer.setLocalIp(container.getLocalIp());
answer.setManualIp(container.getManualIp());
answer.setPublicIp(container.getPublicIp());
answer.setLocalHostName(container.getLocalHostname());
answer.setPublicHostName(container.getPublicHostname());
answer.setResolver(container.getResolver());
answer.setMaximumPort(container.getMaximumPort());
answer.setMinimumPort(container.getMinimumPort());
answer.setGeoLocation(container.getGeoLocation());
answer.setLocation(container.getLocation());
answer.setProcessId(container.getProcessId());
answer.setDebugPort(container.getDebugPort());
answer.setHttpUrl(container.getHttpUrl());
answer.setJmxUrl(container.getJmxUrl());
answer.setJolokiaUrl(container.getJolokiaUrl());
answer.setSshUrl(container.getSshUrl());
answer.setProvisionException(container.getProvisionException());
answer.setProvisionResult(container.getProvisionResult());
answer.setProvisionStatus(container.getProvisionStatus());
answer.setProvisionList(container.getProvisionList());
answer.setJmxDomains(container.getJmxDomains());
answer.setAlive(container.isAlive());
answer.setAliveAndOK(container.isAliveAndOK());
answer.setEnsembleServer(container.isEnsembleServer());
answer.setManaged(container.isManaged());
answer.setProvisioningComplete(container.isProvisioningComplete());
answer.setProvisioningPending(container.isProvisioningPending());
answer.setRoot(container.isRoot());
answer.setStartLink(baseApiLink + "/container/" + containerId + "/start");
return answer;
}
use of io.fabric8.api.Container in project fabric8 by jboss-fuse.
the class FabricWebRegistrationHandler method registerWebapp.
/**
* Registers a webapp to the registry.
*/
private void registerWebapp(Container container, WebEvent webEvent) {
String id = container.getId();
String url = "${zk:" + id + "/http}" + webEvent.getContextPath();
String bundleName = webEvent.getBundle().getSymbolicName();
String bundleVersion = webEvent.getBundle().getVersion().toString();
setJolokiaUrl(container, url, bundleName);
Version version = container.getVersion();
String versionId = version != null ? version.getId() : null;
String json = "{\"id\":" + jsonEncodeString(id) + ",\"services\":[" + jsonEncodeString(url) + "]" + ",\"version\":" + JsonHelper.jsonEncodeString(versionId) + ",\"bundleName\":" + jsonEncodeString(bundleName) + ",\"bundleVersion\":" + jsonEncodeString(bundleVersion) + ",\"container\":" + jsonEncodeString(id) + "}";
try {
synchronized (webEvent.getBundle()) {
setData(curator.get(), ZkPath.WEBAPPS_CONTAINER.getPath(bundleName, webEvent.getBundle().getVersion().toString(), id), json, CreateMode.EPHEMERAL);
}
} catch (Exception e) {
LOGGER.error("Failed to register webapp {}.", webEvent.getContextPath(), e);
}
}
use of io.fabric8.api.Container in project kubernetes by ballerinax.
the class DeploymentHandler method generate.
/**
* Generate kubernetes deployment definition from annotation.
*
* @return Generated kubernetes @{@link Deployment} definition
* @throws KubernetesPluginException If an error occurs while generating artifact.
*/
public String generate() throws KubernetesPluginException {
List<ContainerPort> containerPorts = null;
if (deploymentModel.getPorts() != null) {
containerPorts = populatePorts(deploymentModel.getPorts());
}
Container container = generateContainer(deploymentModel, containerPorts);
Deployment deployment = new DeploymentBuilder().withNewMetadata().withName(deploymentModel.getName()).withNamespace(deploymentModel.getNamespace()).withLabels(deploymentModel.getLabels()).endMetadata().withNewSpec().withReplicas(deploymentModel.getReplicas()).withNewTemplate().withNewMetadata().addToLabels(deploymentModel.getLabels()).endMetadata().withNewSpec().withContainers(container).withVolumes(populateVolume(deploymentModel)).endSpec().endTemplate().endSpec().build();
try {
return SerializationUtils.dumpWithoutRuntimeStateAsYaml(deployment);
} catch (JsonProcessingException e) {
String errorMessage = "Error while parsing yaml file for deployment: " + deploymentModel.getName();
throw new KubernetesPluginException(errorMessage, e);
}
}
use of io.fabric8.api.Container in project fabric8 by jboss-fuse.
the class ExampleCamelClusterTest method testRegistryEntries.
@Test
public void testRegistryEntries() throws Exception {
System.out.println(executeCommand("fabric:create -n --wait-for-provisioning root"));
// System.out.println(executeCommand("shell:info"));
// System.out.println(executeCommand("fabric:info"));
// System.out.println(executeCommand("fabric:profile-list"));
ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(bundleContext, FabricService.class);
try {
FabricService fabricService = fabricProxy.getService();
CuratorFramework curator = fabricService.adapt(CuratorFramework.class);
Set<ContainerProxy> containers = ContainerBuilder.create(fabricProxy, 3).withName("fabric-camel").assertProvisioningResult().build();
try {
// We will use the first container as a client and the rest as servers.
LinkedList<Container> containerList = new LinkedList<Container>(containers);
Container client = containerList.removeLast();
LinkedList<Container> servers = new LinkedList<Container>(containerList);
for (Container c : servers) {
Profile p1 = c.getVersion().getRequiredProfile("feature-camel");
Profile p2 = c.getVersion().getRequiredProfile("example-camel-cluster-cluster.server");
c.setProfiles(new Profile[] { p1, p2 });
}
Provision.provisioningSuccess(servers, PROVISION_TIMEOUT);
Profile p1 = client.getVersion().getRequiredProfile("feature-camel");
Profile p2 = client.getVersion().getRequiredProfile("example-camel-cluster-cluster.client");
client.setProfiles(new Profile[] { p1, p2 });
Provision.provisioningSuccess(Arrays.asList(new Container[] { client }), PROVISION_TIMEOUT);
System.out.println(executeCommand("fabric:container-list"));
System.out.println(executeCommand("fabric:profile-display --overlay fabric-camel-server"));
// Check that the entries have been properly propagated.
Assert.assertNotNull(exists(curator, "/fabric/registry/camel/endpoints"));
Assert.assertEquals(1, getChildren(curator, "/fabric/registry/camel/endpoints").size());
Assert.assertTrue(Provision.waitForCondition(Arrays.asList(client), new ContainerCondition() {
@Override
public Boolean checkConditionOnContainer(final Container c) {
return getCompletedExchangesCount(c) > 0;
}
}, 60000L));
// We want to kill all but one server, so we take out the first and keep it to the end.
Container lastActiveServerContainer = servers.removeLast();
for (Container c : servers) {
try {
c.destroy(true);
} catch (Exception ex) {
// ignore.
}
// Get the number of exchanges completed before we kill the server.
final int completed = getCompletedExchangesCount(client);
// Ensure that we still have messages flowing
Assert.assertTrue(Provision.waitForCondition(Arrays.asList(client), new ContainerCondition() {
@Override
public Boolean checkConditionOnContainer(final Container c) {
return getCompletedExchangesCount(c) > completed + 3;
}
}, 60000L));
}
System.out.println(new AnsiString(executeCommand("fabric:container-connect -u admin -p admin " + client.getId() + " camel:route-info fabric-client")).getPlain().toString());
} finally {
ContainerBuilder.destroy(containers);
}
} finally {
fabricProxy.close();
}
}
Aggregations