Search in sources :

Example 36 with Path

use of io.fabric8.annotations.Path in project fabric8 by jboss-fuse.

the class JMXCommandActionSupport method asResults.

protected List<JMXResult> asResults(String path, List<String> responses, Class<?> resultClass) throws Exception {
    ObjectMapper mapper = getObjectMapper();
    List<JMXResult> results = new LinkedList<>();
    for (String responsePath : responses) {
        byte[] bytes = curator.getData().forPath(path + "/" + responsePath);
        String response = PublicStringSerializer.deserialize(bytes);
        JMXResult result = mapper.readValue(response, JMXResult.class);
        if (result.getResponse() instanceof String) {
            try {
                result.setResponse(mapper.readValue((String) result.getResponse(), resultClass));
            } catch (JsonMappingException | IllegalArgumentException ignore) {
                continue;
            }
        }
        results.add(result);
    }
    mapper.getTypeFactory().clearCache();
    return results;
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JMXResult(io.fabric8.api.commands.JMXResult) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LinkedList(java.util.LinkedList)

Example 37 with Path

use of io.fabric8.annotations.Path in project fabric8 by jboss-fuse.

the class ContainerCreateCloud method doExecute.

@Override
protected Object doExecute() throws Exception {
    // validate input before creating containers
    preCreateContainer(name);
    FabricValidations.validateProfileNames(profiles);
    if (isEnsembleServer && newUserPassword == null) {
        newUserPassword = zookeeperPassword != null ? zookeeperPassword : fabricService.getZookeeperPassword();
    }
    CreateJCloudsContainerOptions.Builder builder = CreateJCloudsContainerOptions.builder().name(name).bindAddress(bindAddress).resolver(resolver).manualIp(manualIp).ensembleServer(isEnsembleServer).credential(credential).group(group).hardwareId(hardwareId).identity(identity).osFamily(osFamily).osVersion(osVersion).imageId(imageId).instanceType(instanceType).locationId(locationId).number(number).nodeOptions(CloudUtils.parseProviderOptions(options)).owner(owner).adminAccess(!disableAdminAccess).publicKeyFile(publicKeyFile).contextName(contextName).providerName(providerName).apiName(apiName).user(user).password(password).proxyUri(proxyUri != null ? proxyUri : fabricService.getMavenRepoURI()).zookeeperUrl(fabricService.getZookeeperUrl()).zookeeperPassword(isEnsembleServer && zookeeperPassword != null ? zookeeperPassword : fabricService.getZookeeperPassword()).jvmOpts(jvmOpts).environmentalVariable(environmentalVariables).version(version).withUser(newUser, newUserPassword, newUserRole).profiles(getProfileNames()).dataStoreProperties(getDataStoreProperties()).uploadDistribution(!distributionUploadDisable);
    if (path != null && !path.isEmpty()) {
        builder.path(path);
    }
    CreateContainerMetadata[] metadatas = fabricService.createContainers(builder.build(), new PrintStreamCreationStateListener(System.out));
    if (isEnsembleServer && metadatas != null && metadatas.length > 0 && metadatas[0].isSuccess()) {
        ShellUtils.storeZookeeperPassword(session, metadatas[0].getCreateOptions().getZookeeperPassword());
    }
    // display containers
    displayContainers(metadatas);
    return null;
}
Also used : PrintStreamCreationStateListener(io.fabric8.internal.PrintStreamCreationStateListener) CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata) CreateJCloudsContainerOptions(io.fabric8.service.jclouds.CreateJCloudsContainerOptions)

Example 38 with Path

use of io.fabric8.annotations.Path in project fabric8 by jboss-fuse.

the class SubsystemResolver method prepare.

public void prepare(Collection<Feature> allFeatures, Map<String, Set<String>> requirements, Map<String, Set<BundleRevision>> system) throws Exception {
    // Build subsystems on the fly
    for (Map.Entry<String, Set<String>> entry : requirements.entrySet()) {
        String[] parts = entry.getKey().split("/");
        if (root == null) {
            root = new Subsystem(parts[0]);
        } else if (!root.getName().equals(parts[0])) {
            throw new IllegalArgumentException("Can not use multiple roots: " + root.getName() + ", " + parts[0]);
        }
        Subsystem ss = root;
        for (int i = 1; i < parts.length; i++) {
            ss = getOrCreateChild(ss, parts[i]);
        }
        for (String requirement : entry.getValue()) {
            ss.require(requirement);
        }
    }
    if (root == null) {
        return;
    }
    // Pre-resolve
    root.build(allFeatures);
    // Add system resources
    BundleRevision sysBundleRev = null;
    boolean hasEeCap = false;
    for (Map.Entry<String, Set<BundleRevision>> entry : system.entrySet()) {
        Subsystem ss = null;
        String[] parts = entry.getKey().split("/");
        String path = parts[0];
        if (path.equals(root.getName())) {
            ss = root;
        }
        for (int i = 1; ss != null && i < parts.length; i++) {
            path += "/" + parts[i];
            ss = ss.getChild(path);
        }
        if (ss != null) {
            ResourceImpl dummy = new ResourceImpl("dummy", "dummy", Version.emptyVersion);
            for (BundleRevision res : entry.getValue()) {
                // We need to explicitely provide service capabilities for bundles
                // We use both actual services and services declared from the headers
                // TODO: use actual services
                Map<String, String> headers = new DictionaryAsMap<>(res.getBundle().getHeaders());
                Resource tmp = ResourceBuilder.build(res.getBundle().getLocation(), headers);
                for (Capability cap : tmp.getCapabilities(ServiceNamespace.SERVICE_NAMESPACE)) {
                    dummy.addCapability(new CapabilityImpl(dummy, cap.getNamespace(), cap.getDirectives(), cap.getAttributes()));
                }
                ss.addSystemResource(res);
                for (Capability cap : res.getCapabilities(null)) {
                    hasEeCap |= cap.getNamespace().equals(EXECUTION_ENVIRONMENT_NAMESPACE);
                }
                if (res.getBundle().getBundleId() == 0) {
                    sysBundleRev = res;
                }
            }
            ss.addSystemResource(dummy);
        }
    }
    // Under Equinox, the osgi.ee capabilities are not provided by the system bundle
    if (!hasEeCap && sysBundleRev != null) {
        String provideCaps = sysBundleRev.getBundle().getHeaders().get(PROVIDE_CAPABILITY);
        environmentResource = new ResourceImpl("environment", "karaf.environment", Version.emptyVersion);
        environmentResource.addCapabilities(ResourceBuilder.parseCapability(environmentResource, provideCaps));
        root.addSystemResource(environmentResource);
    }
}
Also used : CapabilitySet(io.fabric8.agent.resolver.CapabilitySet) Set(java.util.Set) Capability(org.osgi.resource.Capability) DictionaryAsMap(org.apache.felix.utils.collections.DictionaryAsMap) Resource(org.osgi.resource.Resource) ResourceImpl(io.fabric8.agent.resolver.ResourceImpl) CapabilityImpl(io.fabric8.agent.resolver.CapabilityImpl) BundleRevision(org.osgi.framework.wiring.BundleRevision) HashMap(java.util.HashMap) DictionaryAsMap(org.apache.felix.utils.collections.DictionaryAsMap) Map(java.util.Map)

Example 39 with Path

use of io.fabric8.annotations.Path in project fabric8 by jboss-fuse.

the class ContainerResource method stop.

/**
 * Stops the container
 */
@DELETE
@Path("start")
public void stop() {
    FabricService fabricService = getFabricService();
    Objects.notNull(fabricService, "fabricService");
    fabricService.stopContainer(container);
}
Also used : FabricService(io.fabric8.api.FabricService) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 40 with Path

use of io.fabric8.annotations.Path in project fabric8 by jboss-fuse.

the class FabricResource method version.

/**
 * Accesses a version resource
 */
@Path("version/{versionId}")
public VersionResource version(@PathParam("versionId") String versionId) {
    FabricService fabricService = getFabricService();
    if (fabricService != null && Strings.isNotBlank(versionId)) {
        ProfileService profileService = fabricService.adapt(ProfileService.class);
        Version version = profileService.getRequiredVersion(versionId);
        if (version != null) {
            return new VersionResource(this, version);
        } else {
            LOG.warn("No version found for: {}", version);
        }
    }
    return null;
}
Also used : ProfileService(io.fabric8.api.ProfileService) Version(io.fabric8.api.Version) FabricService(io.fabric8.api.FabricService) Path(javax.ws.rs.Path)

Aggregations

Test (org.junit.Test)45 File (java.io.File)41 IOException (java.io.IOException)34 ArrayList (java.util.ArrayList)18 PathTestUtil.createTmpFile (io.fabric8.maven.docker.util.PathTestUtil.createTmpFile)17 HashMap (java.util.HashMap)12 ResourceConfig (io.fabric8.maven.core.config.ResourceConfig)11 VolumeConfig (io.fabric8.maven.core.config.VolumeConfig)11 Path (java.nio.file.Path)11 FabricService (io.fabric8.api.FabricService)10 RuntimeProperties (io.fabric8.api.RuntimeProperties)9 Properties (java.util.Properties)9 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)8 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)8 InputStream (java.io.InputStream)8 Path (javax.ws.rs.Path)8 HttpProxyRule (io.fabric8.gateway.model.HttpProxyRule)7 NodeState (io.fabric8.groups.NodeState)7 URISyntaxException (java.net.URISyntaxException)7 List (java.util.List)6