-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HWKALERTS-50 work continuing, not yet working...
- added a Producer for finally getting a MetricsService injected into the alerts-metrics Manager. And finally got a session started for the hawkular_metrics keyspace. - required a tweak to metrics core to create a session that does not try to install the schema. - figure out how to establish a local MetricsSession for the hawular_metrics - fix bug in fetching triggers by tags cross-tenant - fix issue in ExternalCondition constructor - fix persistence issue - add ExternalCondition handling to setConditions/insert - TODO: overloading condition.operator, pattern. Should we add explicit fields to the schema? - fix issue in test, needed to tag the test trigger as a metrics-trigger. - make the Manager bean @startup so that it gets created immediately, registers its listener and starts looking for expressions to process.
- Loading branch information
Showing
7 changed files
with
211 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
hawkular-alerts-metrics/src/main/java/org/hawkular/alerts/external/metrics/CassCluster.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package org.hawkular.alerts.external.metrics; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
import com.datastax.driver.core.Cluster; | ||
import com.datastax.driver.core.ProtocolVersion; | ||
import com.datastax.driver.core.Session; | ||
|
||
/** | ||
* Cassandra cluster representation and session factory. | ||
* | ||
* @author Lucas Ponce | ||
*/ | ||
public class CassCluster { | ||
private static final Logger log = Logger.getLogger(CassCluster.class); | ||
private static final String ALERTS_CASSANDRA_PORT = "hawkular-alerts-metrics.cassandra-cql-port"; | ||
private static final String ALERTS_CASSANDRA_NODES = "hawkular-alerts-metrics.cassandra-nodes"; | ||
private static final String ALERTS_CASSANDRA_RETRY_ATTEMPTS = "hawkular-alerts-metrics.cassandra-retry-attempts"; | ||
private static final String ALERTS_CASSANDRA_RETRY_TIMEOUT = "hawkular-alerts-metrics.cassandra-retry-timeout"; | ||
|
||
private static Cluster cluster = null; | ||
|
||
private static Session session = null; | ||
|
||
private CassCluster() { } | ||
|
||
public static Session getSession() throws Exception { | ||
if (cluster == null && session == null) { | ||
String cqlPort = System.getProperty(ALERTS_CASSANDRA_PORT, "9042"); | ||
String nodes = System.getProperty(ALERTS_CASSANDRA_NODES, "127.0.0.1"); | ||
int attempts = Integer.parseInt(System.getProperty(ALERTS_CASSANDRA_RETRY_ATTEMPTS, "5")); | ||
int timeout = Integer.parseInt(System.getProperty(ALERTS_CASSANDRA_RETRY_TIMEOUT, "2000")); | ||
/* | ||
It might happen that alerts component is faster than embedded cassandra deployed in hawkular. | ||
We will provide a simple attempt/retry loop to avoid issues at initialization. | ||
*/ | ||
while(session == null && !Thread.currentThread().isInterrupted() && attempts >= 0) { | ||
try { | ||
cluster = new Cluster.Builder() | ||
.addContactPoints(nodes.split(",")) | ||
.withPort(new Integer(cqlPort)) | ||
.withProtocolVersion(ProtocolVersion.V3) | ||
.build(); | ||
session = cluster.connect(); | ||
} catch (Exception e) { | ||
log.warn("Could not connect to Cassandra cluster - assuming is not up yet. Cause: " + | ||
((e.getCause() == null) ? e : e.getCause())); | ||
if (attempts == 0) { | ||
throw e; | ||
} | ||
} | ||
if (session == null) { | ||
log.warn("[" + attempts + "] Retrying connecting to Cassandra cluster in [" + timeout + "]ms..."); | ||
attempts--; | ||
try { | ||
Thread.sleep(timeout); | ||
} catch(InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
} | ||
} | ||
} | ||
} | ||
return session; | ||
} | ||
|
||
public static void shutdown() { | ||
if (session != null && !session.isClosed()) { | ||
session.close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...ts-metrics/src/main/java/org/hawkular/alerts/external/metrics/MetricsServiceProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package org.hawkular.alerts.external.metrics; | ||
|
||
import javax.enterprise.inject.Produces; | ||
|
||
import org.hawkular.metrics.core.api.MetricsService; | ||
import org.hawkular.metrics.core.impl.MetricsServiceImpl; | ||
|
||
import com.datastax.driver.core.Session; | ||
|
||
/** | ||
* @author jay shaughnessy | ||
* @author john sanda | ||
*/ | ||
public class MetricsServiceProducer { | ||
|
||
private MetricsServiceImpl metricsService; | ||
|
||
@Produces | ||
public MetricsService getMetricsService() throws Exception { | ||
if (metricsService == null) { | ||
metricsService = new MetricsServiceImpl(); | ||
String keyspace = "hawkular_metrics"; | ||
Session session = CassCluster.getSession(); | ||
boolean resetDB = false; | ||
boolean createSchema = false; | ||
metricsService.startUp(session, keyspace, resetDB, createSchema); | ||
} | ||
|
||
return metricsService; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters