Search in sources :

Example 31 with Service

use of io.fabric8.patch.Service in project docker-maven-plugin by fabric8io.

the class VolumeServiceTest method testCreateVolumeConfig.

@Test
public void testCreateVolumeConfig() throws Exception {
    final VolumeConfiguration config = new VolumeConfiguration.Builder().name("testVolume").driver("test").opts(withMap("opts")).labels(withMap("labels")).build();
    new Expectations() {

        {
            // Use a 'delegate' to verify the argument given directly. No need
            // for an 'intermediate' return method in the service just to check this.
            docker.createVolume(with(new Delegate<VolumeCreateConfig>() {

                void check(VolumeCreateConfig vcc) {
                    assertThat(vcc.getName(), is("testVolume"));
                    JSONObject vccJson = (JSONObject) JSONParser.parseJSON(vcc.toJson());
                    assertEquals(vccJson.get("Driver"), "test");
                }
            }));
            result = "testVolume";
        }
    };
    String volume = new VolumeService(docker).createVolume(config);
    assertEquals(volume, "testVolume");
}
Also used : Expectations(mockit.Expectations) VolumeCreateConfig(io.fabric8.maven.docker.access.VolumeCreateConfig) JSONObject(org.json.JSONObject) Delegate(mockit.Delegate) VolumeConfiguration(io.fabric8.maven.docker.config.VolumeConfiguration) Test(org.junit.Test)

Example 32 with Service

use of io.fabric8.patch.Service in project kie-wb-common by kiegroup.

the class OpenShiftClient method getDeploymentConfig.

private DeploymentConfig getDeploymentConfig(KubernetesList list, String svcName) {
    if (list != null) {
        List<HasMetadata> items = list.getItems();
        String dcName = null;
        for (HasMetadata item : items) {
            if (item instanceof Service && item.getMetadata().getName().equals(svcName)) {
                Map<String, String> selector = ((Service) item).getSpec().getSelector();
                dcName = selector.get("deploymentconfig");
                if (dcName == null) {
                    dcName = selector.get("deploymentConfig");
                }
                break;
            }
        }
        if (dcName != null) {
            for (HasMetadata item : items) {
                if (item instanceof DeploymentConfig && item.getMetadata().getName().equals(dcName)) {
                    return (DeploymentConfig) item;
                }
            }
        }
    }
    return null;
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Service(io.fabric8.kubernetes.api.model.Service) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) DoneableDeploymentConfig(io.fabric8.openshift.api.model.DoneableDeploymentConfig) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig)

Example 33 with Service

use of io.fabric8.patch.Service in project kie-wb-common by kiegroup.

the class OpenShiftClient method setReplicas.

private void setReplicas(String id, int replicas) throws InterruptedException {
    OpenShiftRuntimeId runtimeId = OpenShiftRuntimeId.fromString(id);
    String prjName = runtimeId.project();
    String svcName = runtimeId.service();
    Service service = delegate.services().inNamespace(prjName).withName(svcName).get();
    DeployableScalableResource<DeploymentConfig, DoneableDeploymentConfig> dcr = getDeploymentConfigResource(service);
    if (dcr != null) {
        DeploymentConfig dc = dcr.get();
        dc.getSpec().setReplicas(replicas);
        dcr.replace(dc);
        dcr.waitUntilReady(buildTimeout, TimeUnit.MILLISECONDS);
    }
}
Also used : DoneableDeploymentConfig(io.fabric8.openshift.api.model.DoneableDeploymentConfig) Service(io.fabric8.kubernetes.api.model.Service) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) DoneableDeploymentConfig(io.fabric8.openshift.api.model.DoneableDeploymentConfig) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig)

Example 34 with Service

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

the class ClusterListAction method printCluster.

protected void printCluster(String dir, PrintStream out) throws Exception {
    // do we have any clusters at all?
    if (exists(getCurator(), dir) == null) {
        return;
    }
    List<String> children = getAllChildren(getCurator(), dir);
    Map<String, Map<String, ClusterNode>> clusters = new TreeMap<String, Map<String, ClusterNode>>();
    for (String child : children) {
        byte[] data = getCurator().getData().forPath(child);
        if (data != null && data.length > 0) {
            String text = new String(data).trim();
            if (!text.isEmpty()) {
                String clusterName = getClusterName(dir, child);
                Map<String, ClusterNode> cluster = clusters.get(clusterName);
                if (cluster == null) {
                    cluster = new TreeMap<String, ClusterNode>();
                    clusters.put(clusterName, cluster);
                }
                ObjectMapper mapper = new ObjectMapper();
                Map<String, Object> map = null;
                try {
                    map = mapper.readValue(data, HashMap.class);
                } catch (JsonParseException e) {
                    log.error("Error parsing JSON string: {}", text);
                    throw e;
                }
                ClusterNode node = null;
                Object id = value(map, "id", "container");
                if (id != null) {
                    Object agent = value(map, "container", "agent");
                    List services = (List) value(map, "services");
                    node = cluster.get(id);
                    if (node == null) {
                        node = new ClusterNode();
                        cluster.put(id.toString(), node);
                    }
                    if (services != null) {
                        if (!services.isEmpty()) {
                            for (Object service : services) {
                                node.services.add(getSubstitutedData(getCurator(), service.toString()));
                            }
                            node.masters.add(agent);
                        } else {
                            node.slaves.add(agent);
                        }
                    } else {
                        Object started = value(map, "started");
                        if (started == Boolean.TRUE) {
                            node.masters.add(agent);
                        } else {
                            node.slaves.add(agent);
                        }
                    }
                }
            }
        }
    }
    TablePrinter table = new TablePrinter();
    table.columns("cluster", "masters", "slaves", "services");
    for (String clusterName : clusters.keySet()) {
        Map<String, ClusterNode> nodes = clusters.get(clusterName);
        table.row(clusterName, "", "", "", "");
        for (String nodeName : nodes.keySet()) {
            ClusterNode node = nodes.get(nodeName);
            table.row("   " + nodeName, printList(node.masters), printList(node.slaves), printList(node.services));
        }
    }
    table.print();
}
Also used : HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) JsonParseException(com.fasterxml.jackson.core.JsonParseException) TablePrinter(io.fabric8.utils.TablePrinter) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 35 with Service

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

the class Deployer method getBundlesToStart.

protected List<Bundle> getBundlesToStart(Collection<Bundle> bundles, Bundle serviceBundle) {
    // Restart the features service last, regardless of any other consideration
    // so that we don't end up with the service trying to do stuff before we're done
    boolean restart = false;
    SortedMap<Integer, Set<Bundle>> bundlesPerStartLevel = new TreeMap<>();
    for (Bundle bundle : bundles) {
        if (bundle == serviceBundle) {
            restart = true;
        } else {
            int sl = bundle.adapt(BundleStartLevel.class).getStartLevel();
            addToMapSet(bundlesPerStartLevel, sl, bundle);
        }
    }
    if (bundlesPerStartLevel.isEmpty()) {
        bundles = Collections.emptyList();
    } else {
        bundles = bundlesPerStartLevel.remove(bundlesPerStartLevel.firstKey());
    }
    List<BundleRevision> revs = new ArrayList<>();
    for (Bundle bundle : bundles) {
        revs.add(bundle.adapt(BundleRevision.class));
    }
    List<Bundle> sorted = new ArrayList<>();
    for (BundleRevision rev : RequirementSort.sort(revs)) {
        sorted.add(rev.getBundle());
    }
    if (sorted.isEmpty() && restart) {
        sorted.add(serviceBundle);
    }
    return sorted;
}
Also used : BundleStartLevel(org.osgi.framework.startlevel.BundleStartLevel) MapUtils.addToMapSet(io.fabric8.agent.internal.MapUtils.addToMapSet) MapUtils.removeFromMapSet(io.fabric8.agent.internal.MapUtils.removeFromMapSet) Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision)

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