Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Modifications:
Browse files Browse the repository at this point in the history
* pull out the testing code
* don't try to do the work of the integration code when making sure
resource types, tenants and envs exist
* make pinger always deployed after inventory.
  • Loading branch information
metlos committed May 22, 2015
1 parent 0e63607 commit e4dc639
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@
*/
package org.hawkular.component.pinger;

import org.hawkular.inventory.api.Action;
import org.hawkular.inventory.api.Interest;
import org.hawkular.inventory.api.Inventory;
import org.hawkular.inventory.api.filters.With;
import org.hawkular.inventory.api.model.Resource;
import org.hawkular.inventory.cdi.Observable;
import org.hawkular.inventory.cdi.ObservableAutoTenant;
import rx.functions.Action1;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.Lock;
import javax.ejb.LockType;
import javax.ejb.Schedule;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -28,29 +45,6 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.Lock;
import javax.ejb.LockType;
import javax.ejb.Schedule;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.inject.Inject;

import org.hawkular.inventory.api.Action;
import org.hawkular.inventory.api.EntityAlreadyExistsException;
import org.hawkular.inventory.api.Interest;
import org.hawkular.inventory.api.Inventory;
import org.hawkular.inventory.api.Tenants.Single;
import org.hawkular.inventory.api.filters.With;
import org.hawkular.inventory.api.model.Environment;
import org.hawkular.inventory.api.model.Resource;
import org.hawkular.inventory.api.model.ResourceType;
import org.hawkular.inventory.api.model.Tenant;
import org.hawkular.inventory.cdi.Observable;

import rx.functions.Action1;

/**
* A SLSB that coordinates the pinging of resources
*
Expand Down Expand Up @@ -129,29 +123,17 @@ public List<PingDestination> getNewUrls() {
@Observable
private Inventory.Mixin.Observable inventory;

@Inject
@ObservableAutoTenant
private Inventory.Mixin.AutoTenantAndObservable autotenantInventory;

final NewUrlsCollector newUrlsCollector = new NewUrlsCollector();

private void addUrl(String tenantId, String envId, String url) {
Log.LOG.infof("Putting url to inventory: %s", url);

Single tenant = null;
try {
tenant = inventory.tenants().create(Tenant.Blueprint.builder().withId(tenantId).build());
} catch (EntityAlreadyExistsException e) {
tenant = inventory.tenants().get(tenantId);
}
try {
tenant.resourceTypes().create(ResourceType.Blueprint.builder().withId("URL").withVersion("1").build());
} catch (EntityAlreadyExistsException e) {
}
org.hawkular.inventory.api.Environments.Single env = null;
try {
env = tenant.environments().create(
Environment.Blueprint.builder().withId(envId).build());
} catch (EntityAlreadyExistsException e) {
env = tenant.environments().get(envId);
}
env.feedlessResources().create(
//we want the magic to happen, so using the autotenant here
autotenantInventory.tenants().get(tenantId).environments().get(envId).feedlessResources().create(
Resource.Blueprint.builder().withId(UUID.randomUUID().toString()).withResourceType("URL")
.withProperty("url", url).build());

Expand All @@ -166,6 +148,8 @@ public void startUp() {
*/
inventory.observable(Interest.in(Resource.class).being(Action.created())).subscribe(newUrlsCollector);

//we must not use the autotenantInventory here, because it would disallow us from "seeing" all the tenants.
//We need that though and at the same time we don't need any of the features offered by autotenant, so it's ok.
Set<Resource> urls = inventory.tenants().getAll().resourceTypes().getAll(With.id(PingDestination.URL_TYPE))
.resources().getAll().entities();
Log.LOG.infof("About to initialize Hawkular Pinger with %d URLs", urls.size());
Expand All @@ -174,11 +158,12 @@ public void startUp() {
destinations.add(PingDestination.from(r));
}

if (destinations.isEmpty()) {
/* for test purposes */
addUrl("jdoe", "test", "http://hawkular.github.io");
}

//eff testing purposes, this causes order-of-initialization problems...
// if (destinations.isEmpty()) {
// /* for test purposes */
// addUrl("jdoe", "test", "http://hawkular.github.io");
// }
//
}

/**
Expand Down
24 changes: 24 additions & 0 deletions modules/pinger/src/main/webapp/WEB-INF/jboss-all.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2015 Red Hat, Inc. and/or its affiliates
and other contributors as indicated by the @author tags.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<jboss umlns="urn:jboss:1.0">
<jboss-deployment-dependencies xmlns="urn:jboss:deployment-dependencies:1.0">
<dependency name="hawkular-integrated-inventory-rest.war"/>
</jboss-deployment-dependencies>
</jboss>

0 comments on commit e4dc639

Please sign in to comment.