Search in sources :

Example 41 with Service

use of io.fabric8.patch.Service in project fabric8 by jboss-fuse.

the class FabricManager method currentContainerConfigurationFiles.

/**
 * Returns a map of all the current configuration files in the profiles of
 * the current container with the file name as the key and the profile ID as
 * the value
 */
@Override
public Map<String, String> currentContainerConfigurationFiles() {
    String containerName = getCurrentContainerName();
    FabricServiceImpl service = fabricService;
    Container container = service.getContainer(containerName);
    if (container != null) {
        Profile[] profiles = container.getProfiles();
        return Profiles.getConfigurationFileNameMap(profiles);
    }
    return new HashMap<String, String>();
}
Also used : Container(io.fabric8.api.Container) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FabricServiceImpl(io.fabric8.service.FabricServiceImpl) Profile(io.fabric8.api.Profile)

Example 42 with Service

use of io.fabric8.patch.Service in project fabric8 by jboss-fuse.

the class JcloudsContainerProvider method create.

@Override
public CreateJCloudsContainerMetadata create(CreateJCloudsContainerOptions input, CreationStateListener listener) throws MalformedURLException, RunNodesException, URISyntaxException, InterruptedException {
    assertValid();
    CreateJCloudsContainerOptions options = input.updateComputeService(getOrCreateComputeService(input));
    listener.onStateChange("Looking up for compute service.");
    ComputeService computeService = getOrCreateComputeService(options);
    if (computeService == null) {
        throw new IllegalStateException("Compute service could not be found or created.");
    }
    Template template = ToTemplate.apply(options);
    listener.onStateChange(String.format(OVERVIEW_FORMAT, 1, options.getContextName()));
    try {
        Set<? extends NodeMetadata> metadata = computeService.createNodesInGroup(options.getGroup(), 1, template);
        if (metadata == null || metadata.size() != 1) {
            throw new IllegalStateException("JClouds created " + metadata.size() + " containers instead of 1");
        }
        NodeMetadata nodeMetadata = metadata.iterator().next();
        switch(nodeMetadata.getStatus()) {
            case RUNNING:
                listener.onStateChange(String.format(NODE_CREATED_FORMAT, nodeMetadata.getName()));
                break;
            default:
                listener.onStateChange(String.format(NODE_ERROR_FORMAT, nodeMetadata.getStatus()));
        }
        CloudContainerInstallationTask installationTask = new CloudContainerInstallationTask(options.getName(), nodeMetadata, options, computeService, firewallManagerFactory.get(), template.getOptions(), listener);
        return installationTask.install();
    } catch (Throwable ex) {
        CreateJCloudsContainerMetadata failureMetadata = new CreateJCloudsContainerMetadata();
        failureMetadata.setCreateOptions(options);
        failureMetadata.setFailure(ex);
        return failureMetadata;
    }
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) ComputeService(org.jclouds.compute.ComputeService) ToTemplate(io.fabric8.service.jclouds.functions.ToTemplate) Template(org.jclouds.compute.domain.Template)

Example 43 with Service

use of io.fabric8.patch.Service in project fabric8 by jboss-fuse.

the class CloudServiceRemove method doExecute.

@Override
protected Object doExecute() throws Exception {
    boolean connected = getCurator().getZookeeperClient().isConnected();
    Container current = null;
    if (connected) {
        deleteSafe(getCurator(), ZkPath.CLOUD_SERVICE.getPath(name));
        current = fabricService.getCurrentContainer();
    }
    // Remove compute configurations for the service.
    Configuration[] computeConfigs = findConfigurationByFactoryPid("org.jclouds.compute");
    if (computeConfigs != null) {
        for (Configuration configuration : computeConfigs) {
            Dictionary props = configuration.getProperties();
            if (props != null) {
                String contextName = (String) props.get(Constants.NAME);
                if (name.equals(contextName)) {
                    configuration.delete();
                }
            }
        }
    }
    return null;
}
Also used : Dictionary(java.util.Dictionary) Container(io.fabric8.api.Container) Configuration(org.osgi.service.cm.Configuration)

Example 44 with Service

use of io.fabric8.patch.Service 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 45 with Service

use of io.fabric8.patch.Service in project fabric8 by jboss-fuse.

the class BaseRepository method addResource.

protected void addResource(Resource resource) {
    for (Capability cap : resource.getCapabilities(null)) {
        String ns = cap.getNamespace();
        CapabilitySet set = capSets.get(ns);
        if (set == null) {
            if ("service-reference".equals(ns) || "osgi.service".equals(ns)) {
                set = new CapabilitySet(Collections.singletonList("objectClass"));
            } else {
                set = new CapabilitySet(Collections.singletonList(ns));
            }
            capSets.put(ns, set);
        }
        set.addCapability(cap);
    }
    resources.add(resource);
}
Also used : Capability(org.osgi.resource.Capability) CapabilitySet(io.fabric8.agent.resolver.CapabilitySet)

Aggregations

Service (io.fabric8.kubernetes.api.model.Service)100 Test (org.junit.Test)78 IOException (java.io.IOException)35 ArrayList (java.util.ArrayList)35 HashMap (java.util.HashMap)33 File (java.io.File)28 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)26 ServiceBuilder (io.fabric8.kubernetes.api.model.ServiceBuilder)24 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)22 Map (java.util.Map)19 Pod (io.fabric8.kubernetes.api.model.Pod)18 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)18 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)18 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)17 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)17 List (java.util.List)17 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)15 Reconciliation (io.strimzi.controller.cluster.Reconciliation)15 ConfigMapOperator (io.strimzi.controller.cluster.operator.resource.ConfigMapOperator)15 ServiceOperator (io.strimzi.controller.cluster.operator.resource.ServiceOperator)15