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;
}
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;
}
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;
}
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();
});
}
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();
});
}
Aggregations