use of io.fabric8.kubernetes.api.model.Condition in project fabric8 by jboss-fuse.
the class SubsystemResolveContext method findProviders.
@Override
public List<Capability> findProviders(Requirement requirement) {
List<Capability> caps = new ArrayList<Capability>();
Region requirerRegion = getRegion(requirement.getResource());
if (requirerRegion != null) {
Map<Requirement, Collection<Capability>> resMap = repository.findProviders(Collections.singleton(requirement));
Collection<Capability> res = resMap != null ? resMap.get(requirement) : null;
if (res != null && !res.isEmpty()) {
caps.addAll(res);
} else if (globalRepository != null) {
// Only bring in external resources for non optional requirements
if (!RESOLUTION_OPTIONAL.equals(requirement.getDirectives().get(RESOLUTION_DIRECTIVE))) {
resMap = globalRepository.findProviders(Collections.singleton(requirement));
res = resMap != null ? resMap.get(requirement) : null;
if (res != null && !res.isEmpty()) {
caps.addAll(res);
}
}
}
// Use the digraph to prune non visible capabilities
Visitor visitor = new Visitor(caps);
requirerRegion.visitSubgraph(visitor);
Collection<Capability> allowed = visitor.getAllowed();
caps.retainAll(allowed);
// the parent one
if (caps.size() > 1) {
Map<String, Resource> providers = new HashMap<String, Resource>();
for (Capability cap : caps) {
Resource resource = cap.getResource();
String id = getSymbolicName(resource) + "|" + getVersion(resource);
Resource prev = providers.get(id);
if (prev != null && prev != resource) {
Region r1 = getRegion(prev);
Region r2 = getRegion(resource);
boolean r2canSeeR1 = isResourceVisibleFromRegion(prev, r2);
boolean r1canSeeR2 = isResourceVisibleFromRegion(resource, r1);
if (r1canSeeR2 && r2canSeeR1) {
// r1 and r2 can see each other
int reqDiff = prev.getRequirements(null).size() - resource.getRequirements(null).size();
if (reqDiff == 0) {
String r1Name = getRegion(prev).getName();
String r2Name = getRegion(resource).getName();
int c = r1Name.compareTo(r2Name);
if (c == 0) {
// One of the resource has to be a bundle, use that one
c = (prev instanceof BundleRevision) ? -1 : +1;
}
resource = c < 0 ? prev : resource;
} else {
// one of the resource has less requirements, so use this one
// This can be the case when one resource has conditionals, which adds further
// requirements to the condition feature.
resource = reqDiff < 0 ? prev : resource;
}
} else {
// only one region can see the other, grab the correct
resource = r1canSeeR2 ? prev : resource;
}
}
providers.put(id, resource);
}
for (Iterator<Capability> it = caps.iterator(); it.hasNext(); ) {
Capability cap = it.next();
if (!providers.values().contains(cap.getResource())) {
it.remove();
}
}
}
// Sort caps
Collections.sort(caps, candidateComparator);
}
return caps;
}
use of io.fabric8.kubernetes.api.model.Condition in project fabric8-maven-plugin by fabric8io.
the class AbstractResourceMojo method writeResourcesIndividualAndComposite.
public static File writeResourcesIndividualAndComposite(KubernetesList resources, File resourceFileBase, ResourceFileType resourceFileType, Logger log, Boolean generateRoute) throws MojoExecutionException {
// Creating a new items list. This will be used to generate openshift.yml
List<HasMetadata> newItemList = new ArrayList<>();
if (!generateRoute) {
// if flag is set false, this will remove the Route resource from resources list
for (HasMetadata item : resources.getItems()) {
if (item.getKind().equalsIgnoreCase("Route")) {
continue;
}
newItemList.add(item);
}
// update the resource with new list
resources.setItems(newItemList);
}
// entity is object which will be sent to writeResource for openshift.yml
// if generateRoute is false, this will be set to resources with new list
// otherwise it will be set to resources with old list.
Object entity = resources;
// if the list contains a single Template lets unwrap it
// in resources already new or old as per condition is set.
// no need to worry about this for dropping Route.
Template template = getSingletonTemplate(resources);
if (template != null) {
entity = template;
}
File file = writeResource(resourceFileBase, entity, resourceFileType);
// write separate files, one for each resource item
// resources passed to writeIndividualResources is also new one.
writeIndividualResources(resources, resourceFileBase, resourceFileType, log, generateRoute);
return file;
}
use of io.fabric8.kubernetes.api.model.Condition in project fabric8 by fabric8io.
the class BrokerProducerConsumerIT method testMQConsumer.
@Test
public void testMQConsumer() throws Exception {
assertThat(client).replicationController(brokerReplicationControllerId).isNotNull();
assertThat(client).replicationController(consumerReplicationControllerId).isNotNull();
assertThat(client).pods().runningStatus().filterNamespace(session.getNamespace()).haveAtLeast(1, new Condition<Pod>() {
@Override
public boolean matches(Pod podSchema) {
return true;
}
});
Asserts.assertWaitFor(10 * 60 * 1000, new Block() {
@Override
public void invoke() throws Exception {
J4pClient brokerClient = jolokiaClients.assertClientForReplicationController(brokerReplicationControllerId);
J4pClient consumerClient = jolokiaClients.assertClientForReplicationController(consumerReplicationControllerId);
assertThat(consumerClient).stringAttribute("org.apache.camel:context=camel-1,type=context,name=\"camel-1\"", "State").isEqualTo("Started");
assertThat(brokerClient).longAttribute("org.apache.activemq:type=Broker,brokerName=default,destinationType=Queue,destinationName=TEST.FOO", "EnqueueCount").isGreaterThan(1000);
assertThat(brokerClient).longAttribute("org.apache.activemq:type=Broker,brokerName=default,destinationType=Queue,destinationName=TEST.FOO", "DequeueCount").isGreaterThan(1000);
}
});
}
use of io.fabric8.kubernetes.api.model.Condition in project fabric8-maven-plugin by fabric8io.
the class ResourceMojo method writeResourcesIndividualAndComposite.
public static File writeResourcesIndividualAndComposite(KubernetesList resources, File resourceFileBase, ResourceFileType resourceFileType, Logger log) throws MojoExecutionException {
// Creating a new items list. This will be used to generate openshift.yml
List<HasMetadata> newItemList = new ArrayList<>();
// entity is object which will be sent to writeResource for openshift.yml
// if generateRoute is false, this will be set to resources with new list
// otherwise it will be set to resources with old list.
Object entity = resources;
// if the list contains a single Template lets unwrap it
// in resources already new or old as per condition is set.
// no need to worry about this for dropping Route.
Template template = getSingletonTemplate(resources);
if (template != null) {
entity = template;
}
File file = writeResource(resourceFileBase, entity, resourceFileType);
// write separate files, one for each resource item
// resources passed to writeIndividualResources is also new one.
writeIndividualResources(resources, resourceFileBase, resourceFileType, log);
return file;
}
use of io.fabric8.kubernetes.api.model.Condition in project strimzi by strimzi.
the class KafkaConnectAssemblyOperatorMockTest method testPauseReconcileUnpause.
@Test
public void testPauseReconcileUnpause(VertxTestContext context) {
setConnectResource(new KafkaConnectBuilder().withMetadata(new ObjectMetaBuilder().withName(CLUSTER_NAME).withNamespace(NAMESPACE).withLabels(TestUtils.map("foo", "bar")).withAnnotations(singletonMap("strimzi.io/pause-reconciliation", "true")).build()).withNewSpec().withReplicas(replicas).endSpec().build());
KafkaConnectApi mock = mock(KafkaConnectApi.class);
when(mock.list(anyString(), anyInt())).thenReturn(Future.succeededFuture(emptyList()));
when(mock.listConnectorPlugins(any(), anyString(), anyInt())).thenReturn(Future.succeededFuture(emptyList()));
Checkpoint async = context.checkpoint();
createConnectCluster(context, mock, true).onComplete(context.succeeding()).compose(v -> {
LOGGER.info("Reconciling again -> update");
return kco.reconcile(new Reconciliation("test-trigger", KafkaConnect.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME));
}).onComplete(context.succeeding(v -> context.verify(() -> {
Resource<KafkaConnect> resource = Crds.kafkaConnectOperation(mockClient).inNamespace(NAMESPACE).withName(CLUSTER_NAME);
if (resource.get().getStatus() == null) {
fail();
}
List<Condition> conditions = resource.get().getStatus().getConditions();
boolean conditionFound = false;
if (conditions != null && !conditions.isEmpty()) {
for (Condition condition : conditions) {
if ("ReconciliationPaused".equals(condition.getType())) {
conditionFound = true;
break;
}
}
}
assertTrue(conditionFound);
async.flag();
}))).compose(v -> {
setConnectResource(new KafkaConnectBuilder().withMetadata(new ObjectMetaBuilder().withName(CLUSTER_NAME).withNamespace(NAMESPACE).withLabels(TestUtils.map("foo", "bar")).withAnnotations(singletonMap("strimzi.io/pause-reconciliation", "false")).build()).withNewSpec().withReplicas(replicas).endSpec().build());
LOGGER.info("Reconciling again -> update");
return kco.reconcile(new Reconciliation("test-trigger", KafkaConnect.RESOURCE_KIND, NAMESPACE, CLUSTER_NAME));
}).onComplete(context.succeeding(v -> context.verify(() -> {
Resource<KafkaConnect> resource = Crds.kafkaConnectOperation(mockClient).inNamespace(NAMESPACE).withName(CLUSTER_NAME);
if (resource.get().getStatus() == null) {
fail();
}
List<Condition> conditions = resource.get().getStatus().getConditions();
boolean conditionFound = false;
if (conditions != null && !conditions.isEmpty()) {
for (Condition condition : conditions) {
if ("ReconciliationPaused".equals(condition.getType())) {
conditionFound = true;
break;
}
}
}
assertFalse(conditionFound);
async.flag();
})));
}
Aggregations