Search in sources :

Example 91 with Resource

use of io.fabric8.support.api.Resource in project fabric8 by jboss-fuse.

the class RequirementSort method sort.

/**
 * Sorts {@link org.osgi.resource.Resource} based on their {@link org.osgi.resource.Requirement}s and {@link org.osgi.resource.Capability}s.
 */
public static <T extends Resource> Collection<T> sort(Collection<T> resources) {
    Set<String> namespaces = new HashSet<>();
    for (Resource r : resources) {
        for (Capability cap : r.getCapabilities(null)) {
            namespaces.add(cap.getNamespace());
        }
    }
    CapabilitySet capSet = new CapabilitySet(new ArrayList<>(namespaces));
    for (Resource r : resources) {
        for (Capability cap : r.getCapabilities(null)) {
            capSet.addCapability(cap);
        }
    }
    Set<T> sorted = new LinkedHashSet<>();
    Set<T> visited = new LinkedHashSet<>();
    for (T r : resources) {
        visit(r, visited, sorted, capSet);
    }
    return sorted;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Capability(org.osgi.resource.Capability) Resource(org.osgi.resource.Resource) CapabilitySet(io.fabric8.agent.resolver.CapabilitySet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 92 with Resource

use of io.fabric8.support.api.Resource in project fabric8 by jboss-fuse.

the class ResourceComparator method compare.

@Override
public int compare(Resource o1, Resource o2) {
    String bsn1 = getSymbolicName(o1);
    String bsn2 = getSymbolicName(o2);
    int c = bsn1.compareTo(bsn2);
    if (c == 0) {
        Version v1 = getVersion(o1);
        Version v2 = getVersion(o2);
        c = v1.compareTo(v2);
        if (c == 0) {
            c = o1.hashCode() - o2.hashCode();
        }
    }
    return c;
}
Also used : Version(org.osgi.framework.Version) ResourceUtils.getVersion(io.fabric8.agent.resolver.ResourceUtils.getVersion)

Example 93 with Resource

use of io.fabric8.support.api.Resource in project fabric8 by jboss-fuse.

the class CommandCollector method collect.

@Override
public List<Resource> collect(ResourceFactory factory) {
    List<Resource> result = new LinkedList<>();
    result.add(factory.createCommandResource("fabric:container-list"));
    if (fabricService != null) {
        Container[] containers = fabricService.getContainers();
        for (Container c : containers) {
            String name = c.getId();
            result.add(factory.createCommandResource("fabric:container-info " + name));
        }
    }
    result.add(factory.createCommandResource("zk:list -r -d"));
    // result.add(new CommandResource("each [1 2 3 ] { echo \"================ Execution $it ==============\"; dev:threads --dump ;  sleep 5000 }"));
    result.add(factory.createCommandResource("camel:context-list"));
    return result;
}
Also used : Container(io.fabric8.api.Container) Resource(io.fabric8.support.api.Resource) LinkedList(java.util.LinkedList)

Example 94 with Resource

use of io.fabric8.support.api.Resource in project strimzi by strimzi.

the class AbtractReadyResourceOperatorTest method waitUntilReadySuccessful.

public void waitUntilReadySuccessful(TestContext context, int unreadyCount) {
    T resource = resource();
    Resource mockResource = mock(resourceType());
    when(mockResource.get()).thenReturn(resource);
    AtomicInteger count = new AtomicInteger();
    when(mockResource.isReady()).then(invocation -> {
        int cnt = count.getAndIncrement();
        if (cnt < unreadyCount) {
            return Boolean.FALSE;
        } else if (cnt == unreadyCount) {
            return Boolean.TRUE;
        } else {
            context.fail("The resource has already been ready once!");
        }
        throw new RuntimeException();
    });
    NonNamespaceOperation mockNameable = mock(NonNamespaceOperation.class);
    when(mockNameable.withName(matches(resource.getMetadata().getName()))).thenReturn(mockResource);
    MixedOperation mockCms = mock(MixedOperation.class);
    when(mockCms.inNamespace(matches(resource.getMetadata().getNamespace()))).thenReturn(mockNameable);
    C mockClient = mock(clientType());
    mocker(mockClient, mockCms);
    AbstractReadyResourceOperator<C, T, L, D, R, P> op = createResourceOperations(vertx, mockClient);
    Async async = context.async();
    op.readiness(NAMESPACE, RESOURCE_NAME, 20, 5_000).setHandler(ar -> {
        assertTrue(ar.succeeded());
        verify(mockResource, times(Readiness.isReadinessApplicable(resource) ? unreadyCount + 1 : 1)).get();
        if (Readiness.isReadinessApplicable(resource)) {
            verify(mockResource, times(unreadyCount + 1)).isReady();
        }
        async.complete();
    });
}
Also used : Resource(io.fabric8.kubernetes.client.dsl.Resource) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Async(io.vertx.ext.unit.Async) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation)

Example 95 with Resource

use of io.fabric8.support.api.Resource in project strimzi by strimzi.

the class AbtractReadyResourceOperatorTest method waitUntilReadyExistenceCheckThrows.

@Test
public void waitUntilReadyExistenceCheckThrows(TestContext context) {
    T resource = resource();
    RuntimeException ex = new RuntimeException();
    Resource mockResource = mock(resourceType());
    when(mockResource.get()).thenThrow(ex);
    NonNamespaceOperation mockNameable = mock(NonNamespaceOperation.class);
    when(mockNameable.withName(matches(resource.getMetadata().getName()))).thenReturn(mockResource);
    MixedOperation mockCms = mock(MixedOperation.class);
    when(mockCms.inNamespace(matches(resource.getMetadata().getNamespace()))).thenReturn(mockNameable);
    C mockClient = mock(clientType());
    mocker(mockClient, mockCms);
    AbstractReadyResourceOperator<C, T, L, D, R, P> op = createResourceOperations(vertx, mockClient);
    Async async = context.async();
    op.readiness(NAMESPACE, RESOURCE_NAME, 20, 100).setHandler(ar -> {
        assertTrue(ar.failed());
        assertThat(ar.cause(), instanceOf(TimeoutException.class));
        verify(mockResource, never()).isReady();
        async.complete();
    });
}
Also used : Resource(io.fabric8.kubernetes.client.dsl.Resource) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Async(io.vertx.ext.unit.Async) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) Test(org.junit.Test)

Aggregations

HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)25 Resource (io.fabric8.kubernetes.client.dsl.Resource)25 Map (java.util.Map)20 Test (org.junit.Test)20 IOException (java.io.IOException)19 HashMap (java.util.HashMap)16 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)14 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)14 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)14 Resource (org.osgi.resource.Resource)14 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)13 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)13 ArrayList (java.util.ArrayList)13 Async (io.vertx.ext.unit.Async)12 File (java.io.File)10 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)9 Service (io.fabric8.kubernetes.api.model.Service)9 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)9 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)8 Bundle (org.osgi.framework.Bundle)7