http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/72a1501c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/JdbcDatabaseHandler.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/JdbcDatabaseHandler.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/JdbcDatabaseHandler.java new file mode 100644 index 0000000..a5448a4 --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/JdbcDatabaseHandler.java @@ -0,0 +1,277 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.eagle.alert.metadata.impl; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.typesafe.config.Config; +import org.apache.eagle.alert.metadata.MetadataUtils; +import org.apache.eagle.alert.metadata.resource.OpResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.sql.*; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +public class JdbcDatabaseHandler { + + private static final Logger LOG = LoggerFactory.getLogger(JdbcDatabaseHandler.class); + + private final String INSERT_STATEMENT = "INSERT INTO %s VALUES (?, ?)"; + private final String DELETE_STATEMENT = "DELETE FROM %s WHERE id=?"; + private final String UPDATE_STATEMENT = "UPDATE %s set value=? WHERE id=?"; + private final String QUERY_ALL_STATEMENT = "SELECT value FROM %s"; + private final String QUERY_CONDITION_STATEMENT = "SELECT value FROM %s WHERE id=?"; + private final String QUERY_ORDERBY_STATEMENT = "SELECT value FROM %s ORDER BY id %s"; + + private Map<String, String> tblNameMap = new HashMap<>(); + + private static final ObjectMapper mapper = new ObjectMapper(); + private Connection connection = null; + + static { + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + } + + public JdbcDatabaseHandler(Config config) { + // "jdbc:mysql://dbhost/database?" + "user=sqluser&password=sqluserpw" + this.tblNameMap = JdbcSchemaManager.tblNameMap; + try { + Class.forName("com.mysql.jdbc.Driver"); + JdbcSchemaManager.getInstance().init(config); + connection = MetadataUtils.getJdbcConnection(config); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + + private String getTableName(String clzName) { + String tbl = tblNameMap.get(clzName); + if (tbl != null) { + return tbl; + } else { + return clzName; + } + } + + public <T> OpResult addOrReplace(String clzName, T t) { + String tb = getTableName(clzName); + OpResult result = new OpResult(); + PreparedStatement statement = null; + Savepoint savepoint = null; + String key = null; + String value = null; + try { + statement = connection.prepareStatement(String.format(INSERT_STATEMENT, tb)); + key = MetadataUtils.getKey(t); + value = mapper.writeValueAsString(t); + + statement.setString(1, key); + Clob clob = connection.createClob(); + clob.setString(1, value); + statement.setClob(2, clob); + + connection.setAutoCommit(false); + savepoint = connection.setSavepoint("insertEntity"); + int status = statement.executeUpdate(); + LOG.info("update {} entities", status); + connection.commit(); + } catch (SQLException e) { + //e.printStackTrace(); + if(e.getMessage().toLowerCase().contains("duplicate")){ + try { + connection.rollback(savepoint); + update(tb, key, value); + } catch (SQLException e1) { + //e1.printStackTrace(); + LOG.warn("Rollback failed"); + } + } + } catch (JsonProcessingException e) { + result.code = OpResult.FAILURE; + result.message = e.getMessage(); + } finally { + if (statement != null) { + try { + statement.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + return result; + } + + private <T> OpResult update(String tb, String key, String value) throws SQLException { + OpResult result = new OpResult(); + PreparedStatement statement = null; + try { + statement = connection.prepareStatement(String.format(UPDATE_STATEMENT, tb)); + Clob clob = connection.createClob(); + clob.setString(1, value); + statement.setClob(1, clob); + statement.setString(2, key); + + int status = statement.executeUpdate(); + LOG.info("update {} entities from table {}", status, tb); + } catch (SQLException e) { + e.printStackTrace(); + result.code = OpResult.FAILURE; + result.message = e.getMessage(); + } finally { + if (statement != null) { + statement.close(); + } + } + return result; + } + + public <T> List<T> list(Class<T> clz) { + String tb = getTableName(clz.getSimpleName()); + List<T> result = new LinkedList<>(); + try { + Statement statement = connection.createStatement(); + ResultSet rs = statement.executeQuery(String.format(QUERY_ALL_STATEMENT, tb)); + while (rs.next()) { + //String key = rs.getString(1); + String json= rs.getString(1); + try { + T obj = mapper.readValue(json, clz); + result.add(obj); + } catch (IOException e) { + LOG.error("deserialize config item failed!", e); + } + } + rs.close(); + statement.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + return result; + } + + public <T> T listWithFilter(String key, Class<T> clz) { + String tb = getTableName(clz.getSimpleName()); + List<T> result = new LinkedList<>(); + PreparedStatement statement = null; + try { + statement = connection.prepareStatement(String.format(QUERY_CONDITION_STATEMENT, tb)); + statement.setString(1, key); + ResultSet rs = statement.executeQuery(); + while (rs.next()) { + //String key = rs.getString(1); + String json= rs.getString(1); + try { + T obj = mapper.readValue(json, clz); + result.add(obj); + } catch (IOException e) { + LOG.error("deserialize config item failed!", e); + } + } + rs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } finally { + if (statement != null) { + try { + statement.close(); + } catch (SQLException e) { + LOG.warn("Close statement failed"); + } + } + } + if (result.isEmpty()) { + return null; + } else { + return result.get(0); + } + } + + public <T> T listTop(Class<T> clz, String sortType) { + String tb = getTableName(clz.getSimpleName()); + List<T> result = new LinkedList<>(); + PreparedStatement statement = null; + try { + statement = connection.prepareStatement(String.format(QUERY_ORDERBY_STATEMENT, tb, sortType)); + ResultSet rs = statement.executeQuery(); + while (rs.next()) { + //String key = rs.getString(1); + String json= rs.getString(1); + try { + T obj = mapper.readValue(json, clz); + result.add(obj); + } catch (IOException e) { + LOG.error("deserialize config item failed!", e); + } + } + rs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } finally { + if (statement != null) { + try { + statement.close(); + } catch (SQLException e) { + LOG.warn("Close statement failed"); + } + } + } + if (result.isEmpty()) { + return null; + } else { + return result.get(0); + } + } + + public <T> OpResult remove(String clzName, String key) { + String tb = getTableName(clzName); + OpResult result = new OpResult(); + try { + PreparedStatement statement = connection.prepareStatement(String.format(DELETE_STATEMENT, tb, key)); + statement.setString(1, key); + int status = statement.executeUpdate(); + String msg = String.format("delete %s entities from table %s", status, tb); + result.code = OpResult.SUCCESS; + result.message = msg; + statement.close(); + } catch (SQLException e) { + result.code = OpResult.FAILURE; + result.message = e.getMessage(); + //e.printStackTrace(); + } + return result; + } + + public void close() throws IOException { + //JdbcSchemaManager.getInstance().shutdown(); + try { + if (this.connection != null) { + this.connection.close(); + } + } catch (SQLException e) { + LOG.warn(e.getMessage()); + } + } + +}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/72a1501c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/JdbcMetadataDaoImpl.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/JdbcMetadataDaoImpl.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/JdbcMetadataDaoImpl.java new file mode 100644 index 0000000..6233938 --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/JdbcMetadataDaoImpl.java @@ -0,0 +1,176 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.eagle.alert.metadata.impl; + +import java.io.IOException; +import java.util.List; + +import com.typesafe.config.Config; +import org.apache.eagle.alert.coordination.model.Kafka2TupleMetadata; +import org.apache.eagle.alert.coordination.model.ScheduleState; +import org.apache.eagle.alert.coordination.model.internal.PolicyAssignment; +import org.apache.eagle.alert.coordination.model.internal.Topology; +import org.apache.eagle.alert.engine.coordinator.PolicyDefinition; +import org.apache.eagle.alert.engine.coordinator.Publishment; +import org.apache.eagle.alert.engine.coordinator.PublishmentType; +import org.apache.eagle.alert.engine.coordinator.StreamDefinition; +import org.apache.eagle.alert.engine.coordinator.StreamingCluster; +import org.apache.eagle.alert.metadata.resource.OpResult; +import org.apache.eagle.alert.metadata.IMetadataDao; +import org.apache.eagle.alert.metadata.resource.Models; + +/** + * @since May 26, 2016 + * + */ +public class JdbcMetadataDaoImpl implements IMetadataDao { + private JdbcDatabaseHandler handler; + + public JdbcMetadataDaoImpl(Config config) { + handler = new JdbcDatabaseHandler(config); + } + + @Override + public List<Topology> listTopologies() { + return handler.list(Topology.class); + } + @Override + public List<StreamingCluster> listClusters() { + return handler.list(StreamingCluster.class); + } + @Override + public List<StreamDefinition> listStreams() { + return handler.list(StreamDefinition.class); + } + @Override + public List<Kafka2TupleMetadata> listDataSources() { + return handler.list(Kafka2TupleMetadata.class); + } + @Override + public List<PolicyDefinition> listPolicies() { + return handler.list(PolicyDefinition.class); + } + @Override + public List<Publishment> listPublishment() { + return handler.list(Publishment.class); + } + @Override + public ScheduleState getScheduleState(String versionId) { + return handler.listWithFilter(versionId, ScheduleState.class); + //return null; + } + @Override + public ScheduleState getScheduleState() { + return handler.listTop(ScheduleState.class, "DESC"); + } + @Override + public List<PolicyAssignment> listAssignments() { + return handler.list(PolicyAssignment.class); + } + @Override + public List<PublishmentType> listPublishmentType() { + return handler.list(PublishmentType.class); + } + + @Override + public OpResult addTopology(Topology t) { + return handler.addOrReplace(Topology.class.getSimpleName(), t); + } + @Override + public OpResult addCluster(StreamingCluster cluster) { + return handler.addOrReplace(StreamingCluster.class.getSimpleName(), cluster); + } + @Override + public OpResult createStream(StreamDefinition stream) { + return handler.addOrReplace(StreamDefinition.class.getSimpleName(), stream); + } + @Override + public OpResult addDataSource(Kafka2TupleMetadata dataSource) { + return handler.addOrReplace(Kafka2TupleMetadata.class.getSimpleName(), dataSource); + } + @Override + public OpResult addPolicy(PolicyDefinition policy) { + return handler.addOrReplace(PolicyDefinition.class.getSimpleName(), policy); + } + @Override + public OpResult addPublishment(Publishment publishment) { + return handler.addOrReplace(Publishment.class.getSimpleName(), publishment); + } + @Override + public OpResult addScheduleState(ScheduleState state) { + return handler.addOrReplace(ScheduleState.class.getSimpleName(), state); + } + @Override + public OpResult addAssignment(PolicyAssignment assignment) { + return handler.addOrReplace(PolicyAssignment.class.getSimpleName(), assignment); + } + @Override + public OpResult addPublishmentType(PublishmentType publishmentType) { + return handler.addOrReplace(PublishmentType.class.getSimpleName(), publishmentType); + } + + @Override + public OpResult removeTopology(String topologyName) { + return handler.remove(Topology.class.getSimpleName(), topologyName); + } + @Override + public OpResult removeCluster(String clusterId) { + return handler.remove(StreamingCluster.class.getSimpleName(), clusterId); + } + @Override + public OpResult removeStream(String streamId) { + return handler.remove(StreamDefinition.class.getSimpleName(), streamId); + } + @Override + public OpResult removeDataSource(String datasourceId) { + return handler.remove(Kafka2TupleMetadata.class.getSimpleName(), datasourceId); + } + @Override + public OpResult removePolicy(String policyId) { + return handler.remove(PolicyDefinition.class.getSimpleName(), policyId); + } + @Override + public OpResult removePublishment(String pubId) { + return handler.remove(Publishment.class.getSimpleName(), pubId); + } + @Override + public OpResult removePublishmentType(String pubType) { + return handler.remove(PublishmentType.class.getSimpleName(), pubType); + } + + @Override + public OpResult clear() { + throw new UnsupportedOperationException("clear not support!"); + } + + @Override + public Models export() { + throw new UnsupportedOperationException("clear not support!"); + } + + @Override + public OpResult importModels(Models models) { + throw new UnsupportedOperationException("clear not support!"); + } + + @Override + public void close() throws IOException { + if (handler != null) { + handler.close(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/72a1501c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/JdbcSchemaManager.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/JdbcSchemaManager.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/JdbcSchemaManager.java new file mode 100644 index 0000000..d9df055 --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/JdbcSchemaManager.java @@ -0,0 +1,151 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.eagle.alert.metadata.impl; + +import com.typesafe.config.Config; +import org.apache.ddlutils.Platform; +import org.apache.ddlutils.PlatformFactory; +import org.apache.ddlutils.model.*; +import org.apache.eagle.alert.coordination.model.Kafka2TupleMetadata; +import org.apache.eagle.alert.coordination.model.ScheduleState; +import org.apache.eagle.alert.coordination.model.internal.PolicyAssignment; +import org.apache.eagle.alert.coordination.model.internal.Topology; +import org.apache.eagle.alert.engine.coordinator.*; +import org.apache.eagle.alert.metadata.MetadataUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Types; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +public class JdbcSchemaManager { + + private final static Logger LOG = LoggerFactory.getLogger(JdbcSchemaManager.class); + private Database database; + private Platform platform; + + private static JdbcSchemaManager instance; + + public static Map<String, String> tblNameMap = new HashMap<>(); + + private JdbcSchemaManager(){} + + private static void registerTableName(String clzName, String tblName){ + tblNameMap.put(clzName, tblName); + } + + static { + registerTableName(StreamingCluster.class.getSimpleName(), "cluster"); + registerTableName(StreamDefinition.class.getSimpleName(), "stream_schema"); + registerTableName(Kafka2TupleMetadata.class.getSimpleName(), "datasource"); + registerTableName(PolicyDefinition.class.getSimpleName(), "policy"); + registerTableName(Publishment.class.getSimpleName(), "publishment"); + registerTableName(PublishmentType.class.getSimpleName(), "publishment_type"); + registerTableName(ScheduleState.class.getSimpleName(), "schedule_state"); + registerTableName(PolicyAssignment.class.getSimpleName(), "assignment"); + registerTableName(Topology.class.getSimpleName(), "topology"); + } + + public static JdbcSchemaManager getInstance(){ + if(instance == null) { + instance = new JdbcSchemaManager(); + } + return instance; + } + + public void init(Config config) { + Connection connection = null; + try { + this.platform = PlatformFactory.createNewPlatformInstance("mysql"); + + connection = MetadataUtils.getJdbcConnection(config); + String dbName = config.getString("database"); + this.database = platform.readModelFromDatabase(connection, dbName); + LOG.info("Loaded " + database); + + Database _database = identifyNewTables(); + if(_database.getTableCount() > 0) { + LOG.info("Creating {} new tables (totally {} tables)", _database.getTableCount(), database.getTableCount()); + this.platform.createTables(connection, _database, false, true); + LOG.info("Created {} new tables: ",_database.getTableCount(), _database.getTables()); + } else { + LOG.debug("All the {} tables have already been created, no new tables", database.getTableCount()); + } + } catch (Exception e) { + LOG.error(e.getMessage(),e); + throw new IllegalStateException(e); + } finally { + if (connection != null){ + try { + connection.close(); + } catch (SQLException e) { + LOG.warn(e.getMessage(),e); + } + } + } + } + + private Database identifyNewTables(){ + Database _database = new Database(); + _database.setName(database.getName()); + Collection<String> tableNames = tblNameMap.values(); + LOG.info("Initializing database and creating tables"); + for (String tableName : tableNames) { + if (database.findTable(tableName) == null) { + Table table = createTable(tableName); + LOG.info("Creating {}", table.toVerboseString()); + _database.addTable(table); + database.addTable(table); + } else { + LOG.debug("Table {} already exists", tableName); + } + } + return _database; + } + + public void shutdown() { + this.platform.shutdownDatabase(); + } + + private Table createTable(String tableName){ + Table table = new Table(); + table.setName(tableName); + buildTable(table); + return table; + } + + private void buildTable(Table table) { + Column id = new Column(); + id.setName("id"); + id.setPrimaryKey(true); + id.setRequired(true); + id.setTypeCode(Types.VARCHAR); + id.setSize("50"); + table.addColumn(id); + + Column value = new Column(); + value.setName("value"); + value.setTypeCode(Types.CLOB); + table.addColumn(value); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/72a1501c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/MetadataDaoFactory.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/MetadataDaoFactory.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/MetadataDaoFactory.java index 94717ce..0b91277 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/MetadataDaoFactory.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/MetadataDaoFactory.java @@ -18,7 +18,7 @@ package org.apache.eagle.alert.metadata.impl; import java.lang.reflect.Constructor; -import org.apache.eagle.alert.metadata.resource.IMetadataDao; +import org.apache.eagle.alert.metadata.IMetadataDao; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,9 +31,10 @@ import com.typesafe.config.ConfigFactory; */ public class MetadataDaoFactory { - private static final MetadataDaoFactory INSTANCE = new MetadataDaoFactory(); private static final Logger LOG = LoggerFactory.getLogger(MetadataDaoFactory.class); + private static final MetadataDaoFactory INSTANCE = new MetadataDaoFactory(); + private IMetadataDao dao; private MetadataDaoFactory() { @@ -49,6 +50,7 @@ public class MetadataDaoFactory { clz = Thread.currentThread().getContextClassLoader().loadClass(clsName); if (IMetadataDao.class.isAssignableFrom(clz)) { Constructor<?> cotr = clz.getConstructor(Config.class); + LOG.info("metadada DAO loaded: " + clsName); dao = (IMetadataDao) cotr.newInstance(datastoreConfig); } else { throw new Exception("metadataDao configuration need to be implementation of IMetadataDao! "); http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/72a1501c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/MongoMetadataDaoImpl.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/MongoMetadataDaoImpl.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/MongoMetadataDaoImpl.java index 608c707..f5794d4 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/MongoMetadataDaoImpl.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/MongoMetadataDaoImpl.java @@ -29,7 +29,8 @@ import org.apache.eagle.alert.engine.coordinator.Publishment; import org.apache.eagle.alert.engine.coordinator.PublishmentType; import org.apache.eagle.alert.engine.coordinator.StreamDefinition; import org.apache.eagle.alert.engine.coordinator.StreamingCluster; -import org.apache.eagle.alert.metadata.resource.IMetadataDao; +import org.apache.eagle.alert.metadata.IMetadataDao; +import org.apache.eagle.alert.metadata.MetadataUtils; import org.apache.eagle.alert.metadata.resource.Models; import org.apache.eagle.alert.metadata.resource.OpResult; import org.bson.BsonDocument; @@ -66,7 +67,7 @@ public class MongoMetadataDaoImpl implements IMetadataDao { private final String connection; private final MongoClient client; - + private MongoDatabase db; private MongoCollection<Document> cluster; private MongoCollection<Document> schema; @@ -156,11 +157,11 @@ public class MongoMetadataDaoImpl implements IMetadataDao { private <T> OpResult addOrReplace(MongoCollection<Document> collection, T t) { BsonDocument filter = new BsonDocument(); if (t instanceof StreamDefinition) { - filter.append("streamId", new BsonString(InMemMetadataDaoImpl.getKey(t))); + filter.append("streamId", new BsonString(MetadataUtils.getKey(t))); } else if (t instanceof PublishmentType) { - filter.append("type", new BsonString(InMemMetadataDaoImpl.getKey(t))); + filter.append("type", new BsonString(MetadataUtils.getKey(t))); } else { - filter.append("name", new BsonString(InMemMetadataDaoImpl.getKey(t))); + filter.append("name", new BsonString(MetadataUtils.getKey(t))); } String json = ""; @@ -379,4 +380,8 @@ public class MongoMetadataDaoImpl implements IMetadataDao { throw new UnsupportedOperationException("importModels not support!"); } + @Override + public void close() throws IOException { + client.close(); + } } http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/72a1501c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/jdbc/JdbcMetadataDaoImpl.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/jdbc/JdbcMetadataDaoImpl.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/jdbc/JdbcMetadataDaoImpl.java deleted file mode 100644 index 9ec119a..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/jdbc/JdbcMetadataDaoImpl.java +++ /dev/null @@ -1,292 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.eagle.alert.metadata.impl.jdbc; - -import java.util.List; - -import org.apache.eagle.alert.coordination.model.Kafka2TupleMetadata; -import org.apache.eagle.alert.coordination.model.ScheduleState; -import org.apache.eagle.alert.coordination.model.internal.PolicyAssignment; -import org.apache.eagle.alert.coordination.model.internal.Topology; -import org.apache.eagle.alert.engine.coordinator.PolicyDefinition; -import org.apache.eagle.alert.engine.coordinator.Publishment; -import org.apache.eagle.alert.engine.coordinator.PublishmentType; -import org.apache.eagle.alert.engine.coordinator.StreamDefinition; -import org.apache.eagle.alert.engine.coordinator.StreamingCluster; -import org.apache.eagle.alert.metadata.resource.OpResult; -import org.apache.eagle.alert.metadata.resource.IMetadataDao; -import org.apache.eagle.alert.metadata.resource.Models; - -/** - * @since May 26, 2016 - * - */ -public class JdbcMetadataDaoImpl implements IMetadataDao { - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#listTopologies() - */ - @Override - public List<Topology> listTopologies() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#addTopology(org.apache.eagle.alert.coordination.model.internal.Topology) - */ - @Override - public OpResult addTopology(Topology t) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#removeTopology(java.lang.String) - */ - @Override - public OpResult removeTopology(String topologyName) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#listClusters() - */ - @Override - public List<StreamingCluster> listClusters() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#addCluster(org.apache.eagle.alert.engine.coordinator.StreamingCluster) - */ - @Override - public OpResult addCluster(StreamingCluster cluster) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#removeCluster(java.lang.String) - */ - @Override - public OpResult removeCluster(String clusterId) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#listStreams() - */ - @Override - public List<StreamDefinition> listStreams() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#createStream(org.apache.eagle.alert.engine.coordinator.StreamDefinition) - */ - @Override - public OpResult createStream(StreamDefinition stream) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#removeStream(java.lang.String) - */ - @Override - public OpResult removeStream(String streamId) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#listDataSources() - */ - @Override - public List<Kafka2TupleMetadata> listDataSources() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#addDataSource(org.apache.eagle.alert.coordination.model.Kafka2TupleMetadata) - */ - @Override - public OpResult addDataSource(Kafka2TupleMetadata dataSource) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#removeDataSource(java.lang.String) - */ - @Override - public OpResult removeDataSource(String datasourceId) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#listPolicies() - */ - @Override - public List<PolicyDefinition> listPolicies() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#addPolicy(org.apache.eagle.alert.engine.coordinator.PolicyDefinition) - */ - @Override - public OpResult addPolicy(PolicyDefinition policy) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#removePolicy(java.lang.String) - */ - @Override - public OpResult removePolicy(String policyId) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#listPublishment() - */ - @Override - public List<Publishment> listPublishment() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#addPublishment(org.apache.eagle.alert.engine.coordinator.Publishment) - */ - @Override - public OpResult addPublishment(Publishment publishment) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#removePublishment(java.lang.String) - */ - @Override - public OpResult removePublishment(String pubId) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#getScheduleState(java.lang.String) - */ - @Override - public ScheduleState getScheduleState(String versionId) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#getScheduleState() - */ - @Override - public ScheduleState getScheduleState() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#addScheduleState(org.apache.eagle.alert.coordination.model.ScheduleState) - */ - @Override - public OpResult addScheduleState(ScheduleState state) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#listAssignments() - */ - @Override - public List<PolicyAssignment> listAssignments() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#addAssignment(org.apache.eagle.alert.coordination.model.internal.PolicyAssignment) - */ - @Override - public OpResult addAssignment(PolicyAssignment assignment) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#clear() - */ - @Override - public OpResult clear() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#export() - */ - @Override - public Models export() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.apache.eagle.service.alert.resource.IMetadataDao#importModels(org.apache.eagle.service.alert.resource.Models) - */ - @Override - public OpResult importModels(Models models) { - // TODO Auto-generated method stub - return null; - } - - @Override - public List<PublishmentType> listPublishmentType() { - // TODO Auto-generated method stub - return null; - } - - @Override - public OpResult addPublishmentType(PublishmentType publishmentType) { - // TODO Auto-generated method stub - return null; - } - - @Override - public OpResult removePublishmentType(String pubType) { - // TODO Auto-generated method stub - return null; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/72a1501c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/resource/IMetadataDao.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/resource/IMetadataDao.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/resource/IMetadataDao.java deleted file mode 100644 index 8eef985..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/resource/IMetadataDao.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.eagle.alert.metadata.resource; - -import java.util.List; - -import org.apache.eagle.alert.coordination.model.Kafka2TupleMetadata; -import org.apache.eagle.alert.coordination.model.ScheduleState; -import org.apache.eagle.alert.coordination.model.internal.PolicyAssignment; -import org.apache.eagle.alert.coordination.model.internal.Topology; -import org.apache.eagle.alert.engine.coordinator.*; - -public interface IMetadataDao { - - List<Topology> listTopologies(); - - OpResult addTopology(Topology t); - - OpResult removeTopology(String topologyName); - - List<StreamingCluster> listClusters(); - - OpResult addCluster(StreamingCluster cluster); - - OpResult removeCluster(String clusterId); - - List<StreamDefinition> listStreams(); - - OpResult createStream(StreamDefinition stream); - - OpResult removeStream(String streamId); - - List<Kafka2TupleMetadata> listDataSources(); - - OpResult addDataSource(Kafka2TupleMetadata dataSource); - - OpResult removeDataSource(String datasourceId); - - List<PolicyDefinition> listPolicies(); - - OpResult addPolicy(PolicyDefinition policy); - - OpResult removePolicy(String policyId); - - List<Publishment> listPublishment(); - - OpResult addPublishment(Publishment publishment); - - OpResult removePublishment(String pubId); - - List<PublishmentType> listPublishmentType(); - - OpResult addPublishmentType(PublishmentType publishmentType); - - OpResult removePublishmentType(String pubType); - - ScheduleState getScheduleState(String versionId); - - ScheduleState getScheduleState(); - - OpResult addScheduleState(ScheduleState state); - - List<PolicyAssignment> listAssignments(); - - OpResult addAssignment(PolicyAssignment assignment); - - // APIs for test friendly - OpResult clear(); - Models export(); - OpResult importModels(Models models); - -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/72a1501c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/resource/OpResult.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/resource/OpResult.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/resource/OpResult.java index 44f507d..3115439 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/resource/OpResult.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/resource/OpResult.java @@ -24,5 +24,7 @@ public class OpResult { public int code = 200; public String message = ""; - + + public static final int SUCCESS = 200; + public static final int FAILURE = 500; } http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/72a1501c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/resources/application.conf ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/resources/application.conf b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/resources/application.conf deleted file mode 100644 index 7213a9f..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/resources/application.conf +++ /dev/null @@ -1,24 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. - - -{ - "datastore": { - "metadataDao": "org.apache.eagle.alert.metadata.impl.InMemMetadataDaoImpl", - "connection": "localhost:27017", - "properties" : { - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/72a1501c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/service/alert/resource/impl/InMemoryTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/service/alert/resource/impl/InMemoryTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/service/alert/resource/impl/InMemoryTest.java index 54a2ffc..645fc2b 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/service/alert/resource/impl/InMemoryTest.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/service/alert/resource/impl/InMemoryTest.java @@ -18,9 +18,11 @@ package org.apache.eagle.service.alert.resource.impl; import org.apache.eagle.alert.engine.coordinator.PolicyDefinition; import org.apache.eagle.alert.metadata.impl.InMemMetadataDaoImpl; -import org.apache.eagle.alert.metadata.resource.IMetadataDao; +import org.apache.eagle.alert.metadata.impl.MetadataDaoFactory; +import org.apache.eagle.alert.metadata.IMetadataDao; import org.junit.Assert; import org.junit.Test; +import org.slf4j.LoggerFactory; import com.typesafe.config.ConfigFactory; @@ -34,6 +36,11 @@ public class InMemoryTest { @Test public void test_AddPolicy() { + + LoggerFactory.getLogger(InMemoryTest.class); + + MetadataDaoFactory.getInstance().getMetadataDao(); + PolicyDefinition pd = new PolicyDefinition(); pd.setName("pd1"); dao.addPolicy(pd); http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/72a1501c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/service/alert/resource/impl/JdbcImplTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/service/alert/resource/impl/JdbcImplTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/service/alert/resource/impl/JdbcImplTest.java new file mode 100644 index 0000000..1a78109 --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/service/alert/resource/impl/JdbcImplTest.java @@ -0,0 +1,167 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.eagle.service.alert.resource.impl; + +import java.io.IOException; +import java.util.Date; +import java.util.List; + +import org.apache.eagle.alert.coordination.model.Kafka2TupleMetadata; +import org.apache.eagle.alert.coordination.model.ScheduleState; +import org.apache.eagle.alert.coordination.model.internal.PolicyAssignment; +import org.apache.eagle.alert.coordination.model.internal.Topology; +import org.apache.eagle.alert.engine.coordinator.PolicyDefinition; +import org.apache.eagle.alert.engine.coordinator.Publishment; +import org.apache.eagle.alert.engine.coordinator.PublishmentType; +import org.apache.eagle.alert.engine.coordinator.StreamingCluster; +import org.apache.eagle.alert.metadata.IMetadataDao; +import org.apache.eagle.alert.metadata.impl.JdbcMetadataDaoImpl; +import org.apache.eagle.alert.metadata.resource.OpResult; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.typesafe.config.Config; +import com.typesafe.config.ConfigFactory; + +public class JdbcImplTest { + private static Logger LOG = LoggerFactory.getLogger(JdbcImplTest.class); + static IMetadataDao dao; + + @BeforeClass + public static void setup() { + System.setProperty("config.resource", "/application-mysql.conf"); + ConfigFactory.invalidateCaches(); + Config config = ConfigFactory.load().getConfig("datastore"); + dao = new JdbcMetadataDaoImpl(config); + } + + @AfterClass + public static void teardown() { + if (dao != null) { + try { + dao.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + private String TOPO_NAME = "topoName"; + + @Ignore @Test + public void test_apis() { + // publishment + { + Publishment publishment = new Publishment(); + publishment.setName("pub-"); + OpResult result = dao.addPublishment(publishment); + Assert.assertEquals(200, result.code); + List<Publishment> assigns = dao.listPublishment(); + Assert.assertEquals(1, assigns.size()); + result = dao.removePublishment("pub-"); + Assert.assertTrue(200 == result.code); + } + // topology + { + OpResult result = dao.addTopology(new Topology(TOPO_NAME, 3, 5)); + System.out.println(result.message); + Assert.assertEquals(200, result.code); + List<Topology> topos = dao.listTopologies(); + Assert.assertEquals(1, topos.size()); + // add again: replace existing one + result = dao.addTopology(new Topology(TOPO_NAME, 4, 5)); + topos = dao.listTopologies(); + Assert.assertEquals(1, topos.size()); + Assert.assertEquals(TOPO_NAME, topos.get(0).getName()); + Assert.assertEquals(4, topos.get(0).getNumOfGroupBolt()); + } + // assignment + { + PolicyAssignment assignment = new PolicyAssignment(); + assignment.setPolicyName("policy1"); + OpResult result = dao.addAssignment(assignment); + Assert.assertEquals(200, result.code); + List<PolicyAssignment> assigns = dao.listAssignments(); + Assert.assertEquals(1, assigns.size()); + } + // cluster + { + StreamingCluster cluster = new StreamingCluster(); + cluster.setName("dd"); + OpResult result = dao.addCluster(cluster); + Assert.assertEquals(200, result.code); + List<StreamingCluster> assigns = dao.listClusters(); + Assert.assertEquals(1, assigns.size()); + } + // data source + { + Kafka2TupleMetadata dataSource = new Kafka2TupleMetadata(); + dataSource.setName("ds"); + OpResult result = dao.addDataSource(dataSource); + Assert.assertEquals(200, result.code); + List<Kafka2TupleMetadata> assigns = dao.listDataSources(); + Assert.assertEquals(1, assigns.size()); + } + // policy + { + PolicyDefinition policy = new PolicyDefinition(); + policy.setName("ds"); + OpResult result = dao.addPolicy(policy); + Assert.assertEquals(200, result.code); + List<PolicyDefinition> assigns = dao.listPolicies(); + Assert.assertEquals(1, assigns.size()); + } + + // publishmentType + { + PublishmentType publishmentType = new PublishmentType(); + publishmentType.setType("KAFKA"); + OpResult result = dao.addPublishmentType(publishmentType); + Assert.assertEquals(200, result.code); + List<PublishmentType> assigns = dao.listPublishmentType(); + Assert.assertEquals(1, assigns.size()); + } + } + + private void test_addstate() { + ScheduleState state = new ScheduleState(); + String versionId = "state-" + System.currentTimeMillis(); + state.setVersion(versionId); + state.setGenerateTime(String.valueOf(new Date().getTime())); + OpResult result = dao.addScheduleState(state); + Assert.assertEquals(200, result.code); + state = dao.getScheduleState(); + Assert.assertEquals(state.getVersion(), versionId); + } + + @Ignore @Test + public void test_readCurrentState() { + test_addstate(); + ScheduleState state = dao.getScheduleState(); + Assert.assertNotNull(state); + + LOG.debug(state.getVersion()); + LOG.debug(state.getGenerateTime()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/72a1501c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/service/alert/resource/impl/MongoImplTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/service/alert/resource/impl/MongoImplTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/service/alert/resource/impl/MongoImplTest.java index afdd91d..e63353b 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/service/alert/resource/impl/MongoImplTest.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/java/org/apache/eagle/service/alert/resource/impl/MongoImplTest.java @@ -28,7 +28,7 @@ import org.apache.eagle.alert.engine.coordinator.Publishment; import org.apache.eagle.alert.engine.coordinator.PublishmentType; import org.apache.eagle.alert.engine.coordinator.StreamingCluster; import org.apache.eagle.alert.metadata.impl.MongoMetadataDaoImpl; -import org.apache.eagle.alert.metadata.resource.IMetadataDao; +import org.apache.eagle.alert.metadata.IMetadataDao; import org.apache.eagle.alert.metadata.resource.OpResult; import org.junit.AfterClass; import org.junit.Assert; http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/72a1501c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/application-mysql.conf ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/application-mysql.conf b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/application-mysql.conf new file mode 100644 index 0000000..55a7121 --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/application-mysql.conf @@ -0,0 +1,22 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. + +{ + "datastore": { + "metadataDao": "org.apache.eagle.alert.metadata.impl.JdbcMetadataDaoImpl", + "connection": "jdbc:mysql://localhost:3306/alert_metadata?user=root&password=&createDatabaseIfNotExist=true", + "database": "alert_metadata" + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/72a1501c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/application.conf ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/application.conf b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/application.conf new file mode 100644 index 0000000..7213a9f --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/test/resources/application.conf @@ -0,0 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. + + +{ + "datastore": { + "metadataDao": "org.apache.eagle.alert.metadata.impl.InMemMetadataDaoImpl", + "connection": "localhost:27017", + "properties" : { + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/72a1501c/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/pom.xml ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/pom.xml b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/pom.xml index c54825c..1d4b33d 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/pom.xml +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/pom.xml @@ -10,7 +10,8 @@ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~ See the License for the specific language governing permissions and ~ limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/72a1501c/eagle-core/eagle-alert-parent/eagle-alert/alert-service/pom.xml ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/pom.xml b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/pom.xml new file mode 100644 index 0000000..1cab431 --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/pom.xml @@ -0,0 +1,169 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with ~ + this work for additional information regarding copyright ownership. ~ The + ASF licenses this file to You 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. --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>eagle-alert</artifactId> + <groupId>org.apache.eagle</groupId> + <version>0.5.0-incubating-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>alert-service</artifactId> + <description>Alert Service: Coordinator + Metadata</description> + <packaging>jar</packaging> + + <dependencies> + <dependency> + <groupId>org.apache.eagle</groupId> + <artifactId>alert-coordinator</artifactId> + <version>${project.version}</version> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + </exclusion> + <exclusion> + <artifactId>storm-core</artifactId> + <groupId>org.apache.storm</groupId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.eagle</groupId> + <artifactId>alert-metadata-service</artifactId> + <version>${project.version}</version> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + </exclusion> + <exclusion> + <artifactId>storm-core</artifactId> + <groupId>org.apache.storm</groupId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>com.sun.jersey</groupId> + <artifactId>jersey-json</artifactId> + </dependency> + <!-- dropwizard --> + <dependency> + <groupId>io.dropwizard</groupId> + <artifactId>dropwizard-core</artifactId> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>io.dropwizard</groupId> + <artifactId>dropwizard-jersey</artifactId> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>io.swagger</groupId> + <artifactId>swagger-jersey-jaxrs</artifactId> + <scope>compile</scope> + <exclusions> + <exclusion> + <groupId>com.sun.jersey</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-maven-plugin</artifactId> + <version>9.2.11.v20150529</version> + <configuration> + <scanIntervalSeconds>5</scanIntervalSeconds> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>1.4</version> + <configuration> + <filters> + <filter> + <artifact>*:*</artifact> + <excludes> + <exclude>META-INF/*.SF</exclude> + <exclude>META-INF/*.DSA</exclude> + <exclude>META-INF/*.RSA</exclude> + </excludes> + </filter> + </filters> + </configuration> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>shade</goal> + </goals> + + <configuration> + <shadedArtifactAttached>true</shadedArtifactAttached> + <shadedClassifierName>shaded</shadedClassifierName> + <transformers> + <transformer + implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> + <transformer + implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> + <mainClass>org.apache.eagle.service.app.ServiceApp</mainClass> + </transformer> + </transformers> + + <artifactSet> + <excludes> + <exclude>org.slf4j:slf4j-log4j12</exclude> + </excludes> + </artifactSet> + + </configuration> + </execution> + </executions> + </plugin> + + <!-- change project to war, and use maven-war-plugin to build the war --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-war-plugin</artifactId> + <version>2.6</version> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>war</goal> + </goals> + </execution> + </executions> + </plugin> + + </plugins> + </build> +</project> http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/72a1501c/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/java/org/apache/eagle/service/app/AlertDropWizardConfiguration.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/java/org/apache/eagle/service/app/AlertDropWizardConfiguration.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/java/org/apache/eagle/service/app/AlertDropWizardConfiguration.java new file mode 100644 index 0000000..1d7a70d --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/java/org/apache/eagle/service/app/AlertDropWizardConfiguration.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.eagle.service.app; + +import io.dropwizard.Configuration; + +/** + * @since Jun 27, 2016 + * + */ +public class AlertDropWizardConfiguration extends Configuration { + +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/72a1501c/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/java/org/apache/eagle/service/app/ServiceApp.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/java/org/apache/eagle/service/app/ServiceApp.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/java/org/apache/eagle/service/app/ServiceApp.java new file mode 100644 index 0000000..f89ff68 --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/java/org/apache/eagle/service/app/ServiceApp.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.eagle.service.app; + +import io.dropwizard.Application; +import io.dropwizard.setup.Bootstrap; +import io.dropwizard.setup.Environment; +import io.swagger.jaxrs.config.BeanConfig; +import io.swagger.jaxrs.listing.ApiListingResource; + +import java.util.EnumSet; + +import javax.servlet.DispatcherType; + +import org.apache.eagle.alert.coordinator.CoordinatorListener; +import org.apache.eagle.alert.coordinator.resource.CoordinatorResource; +import org.apache.eagle.alert.resource.SimpleCORSFiler; +import org.apache.eagle.service.metadata.resource.MetadataResource; + +import com.fasterxml.jackson.annotation.JsonInclude; + +/** + * @since Jun 27, 2016 + * + */ +public class ServiceApp extends Application<AlertDropWizardConfiguration> { + + public static void main(String[] args) throws Exception { + new ServiceApp().run(args); + } + + @Override + public String getName() { + return "alert-engine metadata server and coordinator server!"; + } + + @Override + public void initialize(Bootstrap<AlertDropWizardConfiguration> bootstrap) { + } + + @Override + public void run(AlertDropWizardConfiguration configuration, Environment environment) throws Exception { + environment.getApplicationContext().setContextPath("/rest"); + environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL); + + MetadataResource resource = new MetadataResource(); + environment.jersey().register(resource); + + CoordinatorResource coorResource = new CoordinatorResource(); + environment.jersey().register(coorResource); + + // swagger resources + environment.jersey().register(new ApiListingResource()); + BeanConfig swaggerConfig = new BeanConfig(); + swaggerConfig.setTitle("Alert engine service: metadata and coordinator"); + swaggerConfig.setVersion("v1.2"); + swaggerConfig.setBasePath("/rest"); + swaggerConfig + .setResourcePackage("org.apache.eagle.alert.coordinator.resource,org.apache.eagle.service.metadata.resource"); + swaggerConfig.setScan(true); + + // simple CORS filter + environment.servlets().addFilter("corsFilter", new SimpleCORSFiler()) + .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); + + // context listener + environment.servlets().addServletListeners(new CoordinatorListener()); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/72a1501c/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/resources/application.conf ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/resources/application.conf b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/resources/application.conf new file mode 100644 index 0000000..c04a4ab --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/resources/application.conf @@ -0,0 +1,45 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. + +{ + "coordinator" : { + "policiesPerBolt" : 5, + "boltParallelism" : 5, + "policyDefaultParallelism" : 5, + "boltLoadUpbound": 0.8, + "topologyLoadUpbound" : 0.8, + "numOfAlertBoltsPerTopology" : 5, + "zkConfig" : { + "zkQuorum" : "127.0.0.1:2181", + "zkRoot" : "/alert", + "zkSessionTimeoutMs" : 10000, + "connectionTimeoutMs" : 10000, + "zkRetryTimes" : 3, + "zkRetryInterval" : 3000 + }, + "metadataService" : { + "host" : "localhost", + "port" : 8080, + "context" : "/rest" + }, + "metadataDynamicCheck" : { + "initDelayMillis" : 1000, + "delayMillis" : 30000 + } + }, + "datastore": { + "metadataDao": "org.apache.eagle.alert.metadata.impl.InMemMetadataDaoImpl" + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/72a1501c/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/resources/log4j.properties b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/resources/log4j.properties new file mode 100644 index 0000000..d4bc126 --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/resources/log4j.properties @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. + +log4j.rootLogger=INFO, stdout + +# standard output +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} %p [%t] %c{2}[%L]: %m%n http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/72a1501c/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/webapp/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/webapp/WEB-INF/web.xml b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..c8c4707 --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,91 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more + ~ contributor license agreements. See the NOTICE file distributed with + ~ this work for additional information regarding copyright ownership. + ~ The ASF licenses this file to You 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. + --> +<web-app xmlns="http://java.sun.com/xml/ns/javaee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee + http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" + version="3.0"> + <welcome-file-list> + <welcome-file>index.html</welcome-file> + </welcome-file-list> + + <listener> + <listener-class>org.apache.eagle.alert.coordinator.CoordinatorListener</listener-class> + </listener> + + <servlet> + <servlet-name>Jersey Web Application</servlet-name> + <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> + <init-param> + <param-name>com.sun.jersey.config.property.packages</param-name> + <param-value>io.swagger.jaxrs.json,io.swagger.jaxrs.listing,org.apache.eagle,org.codehaus.jackson.jaxrs</param-value> + </init-param> + <init-param> + <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name> + <param-value>com.sun.jersey.api.container.filter.GZIPContentEncodingFilter;com.sun.jersey.api.container.filter.PostReplaceFilter</param-value> + </init-param> + <init-param> + <param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name> + <param-value>com.sun.jersey.api.container.filter.GZIPContentEncodingFilter</param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <!-- Servlet for swagger initialization only, no URL mapping. --> + <servlet> + <servlet-name>swaggerConfig</servlet-name> + <servlet-class>io.swagger.jaxrs.config.DefaultJaxrsConfig</servlet-class> + <init-param> + <param-name>api.version</param-name> + <param-value>1.0.0</param-value> + </init-param> + <init-param> + <param-name>swagger.api.basepath</param-name> + <param-value>/rest</param-value> + </init-param> + <load-on-startup>2</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>Jersey Web Application</servlet-name> + <url-pattern>/rest/*</url-pattern> + </servlet-mapping> + <filter> + <filter-name>CorsFilter</filter-name> + <!-- this should be replaced by tomcat ones, see also metadata resource --> + <filter-class>org.apache.eagle.alert.resource.SimpleCORSFiler</filter-class> + <init-param> + <param-name>cors.allowed.origins</param-name> + <param-value>*</param-value> + </init-param> + <init-param> + <param-name>cors.allowed.headers</param-name> + <param-value>Authorization,Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With, Accept</param-value> + </init-param> + <init-param> + <param-name>cors.allowed.methods</param-name> + <param-value>GET,POST,HEAD,OPTIONS,PUT,DELETE</param-value> + </init-param> + <init-param> + <param-name>cors.support.credentials</param-name> + <param-value>true</param-value> + </init-param> + </filter> + <filter-mapping> + <filter-name>CorsFilter</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> +</web-app> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/72a1501c/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/webapp/index.html ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/webapp/index.html b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/webapp/index.html new file mode 100644 index 0000000..ef8bf54 --- /dev/null +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-service/src/main/webapp/index.html @@ -0,0 +1,19 @@ +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you 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. + --> + +Alert Services: Coordinator + Metadata Service \ No newline at end of file
