Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D196D200C5A for ; Mon, 3 Apr 2017 13:54:12 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id CAA2F160BC9; Mon, 3 Apr 2017 11:54:12 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 259B0160B8F for ; Mon, 3 Apr 2017 13:54:10 +0200 (CEST) Received: (qmail 76302 invoked by uid 500); 3 Apr 2017 11:54:10 -0000 Mailing-List: contact commits-help@eagle.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@eagle.apache.org Delivered-To: mailing list commits@eagle.apache.org Received: (qmail 76246 invoked by uid 99); 3 Apr 2017 11:54:10 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Apr 2017 11:54:10 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 16D30DF965; Mon, 3 Apr 2017 11:54:10 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: hao@apache.org To: commits@eagle.apache.org Date: Mon, 03 Apr 2017 11:54:12 -0000 Message-Id: In-Reply-To: <04280246f21e4dcd9fbfe899c4344da2@git.apache.org> References: <04280246f21e4dcd9fbfe899c4344da2@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [04/84] [partial] eagle git commit: Clean repo for eagle site archived-at: Mon, 03 Apr 2017 11:54:13 -0000 http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationAction.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationAction.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationAction.java deleted file mode 100644 index 3733e4d..0000000 --- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationAction.java +++ /dev/null @@ -1,205 +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.app.service; - -import com.google.common.base.Preconditions; -import com.typesafe.config.Config; -import com.typesafe.config.ConfigFactory; -import org.apache.eagle.alert.coordination.model.Kafka2TupleMetadata; -import org.apache.eagle.alert.coordination.model.Tuple2StreamMetadata; -import org.apache.eagle.alert.engine.coordinator.StreamDefinition; -import org.apache.eagle.alert.engine.scheme.JsonScheme; -import org.apache.eagle.alert.engine.scheme.JsonStringStreamNameSelector; -import org.apache.eagle.alert.metadata.IMetadataDao; -import org.apache.eagle.alert.metric.MetricConfigs; -import org.apache.eagle.alert.utils.AlertConstants; -import org.apache.eagle.app.Application; -import org.apache.eagle.app.environment.ExecutionRuntime; -import org.apache.eagle.app.environment.ExecutionRuntimeManager; -import org.apache.eagle.app.messaging.KafkaStreamSinkConfig; -import org.apache.eagle.app.messaging.KafkaStreamSourceConfig; -import org.apache.eagle.metadata.model.ApplicationEntity; -import org.apache.eagle.metadata.model.StreamSourceConfig; -import org.apache.eagle.metadata.utils.StreamIdConversions; -import org.apache.eagle.metadata.model.StreamDesc; -import org.apache.eagle.metadata.model.StreamSinkConfig; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.Serializable; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.HashMap; -import java.util.Properties; -import java.util.stream.Collectors; - -/** - * Managed Application Action: org.apache.eagle.app.service.ApplicationAction - *

    - *
  • Application Metadata Entity (Persistence): org.apache.eagle.metadata.model.ApplicationEntity
  • - *
  • Application Processing Logic (Execution): org.apache.eagle.app.Application
  • - *
  • Application Lifecycle Listener (Installation): org.apache.eagle.app.ApplicationLifecycle
  • - *
- */ -public class ApplicationAction implements Serializable { - private final Config effectiveConfig; - private final Application application; - private final ExecutionRuntime runtime; - private final ApplicationEntity metadata; - private final IMetadataDao alertMetadataService; - private static final String APP_METRIC_PREFIX = "eagle."; - private static final Logger LOG = LoggerFactory.getLogger(ApplicationAction.class); - - /** - * @param metadata ApplicationEntity. - * @param application Application. - */ - public ApplicationAction(Application application, ApplicationEntity metadata, Config serverConfig, IMetadataDao alertMetadataService) { - Preconditions.checkNotNull(application, "Application is null"); - Preconditions.checkNotNull(metadata, "ApplicationEntity is null"); - this.application = application; - this.metadata = metadata; - this.runtime = ExecutionRuntimeManager.getInstance().getRuntime(application.getEnvironmentType(), serverConfig); - Map executionConfig = new HashMap<>(metadata.getConfiguration()); - if (executionConfig == null) { - executionConfig = Collections.emptyMap(); - } - if (serverConfig.hasPath(MetricConfigs.METRIC_PREFIX_CONF)) { - LOG.warn("Ignored sever config {} = {}", MetricConfigs.METRIC_PREFIX_CONF, serverConfig.getString(MetricConfigs.METRIC_PREFIX_CONF)); - } - - executionConfig.put("jarPath", metadata.getJarPath()); - executionConfig.put("mode", metadata.getMode().name()); - executionConfig.put(MetricConfigs.METRIC_PREFIX_CONF, APP_METRIC_PREFIX); - - if (serverConfig.hasPath(AlertConstants.COORDINATOR)) { - this.effectiveConfig = ConfigFactory.parseMap(executionConfig) - .withFallback(serverConfig) - .withFallback(ConfigFactory.parseMap(metadata.getContext())) - .withFallback(serverConfig.getConfig(AlertConstants.COORDINATOR)); - } else { - this.effectiveConfig = ConfigFactory.parseMap(executionConfig) - .withFallback(serverConfig) - .withFallback(ConfigFactory.parseMap(metadata.getContext())); - } - this.alertMetadataService = alertMetadataService; - } - - public void doInstall() { - processStreams(); - } - - private void processStreams() { - if (metadata.getDescriptor().getStreams() == null) { - return; - } - - List streamDescToInstall = metadata.getDescriptor().getStreams().stream().map((streamDefinition -> { - StreamDefinition copied = streamDefinition.copy(); - copied.setSiteId(metadata.getSite().getSiteId()); - copied.setStreamId(StreamIdConversions.formatSiteStreamId(metadata.getSite().getSiteId(), copied.getStreamId())); - StreamSinkConfig streamSinkConfig = this.runtime.environment() - .stream().getSinkConfig(StreamIdConversions.parseStreamTypeId(copied.getSiteId(), copied.getStreamId()), this.effectiveConfig); - - StreamSourceConfig streamSourceConfig = null; - - try { - streamSourceConfig = this.runtime.environment() - .stream().getSourceConfig(StreamIdConversions.parseStreamTypeId(copied.getSiteId(), copied.getStreamId()), this.effectiveConfig); - } catch (Throwable throwable) { - // Ignore source config if not set. - } - - StreamDesc streamDesc = new StreamDesc(); - streamDesc.setSchema(copied); - streamDesc.setSinkConfig(streamSinkConfig); - streamDesc.setSourceConfig(streamSourceConfig); - streamDesc.setStreamId(copied.getStreamId()); - - return streamDesc; - })).collect(Collectors.toList()); - metadata.setStreams(streamDescToInstall); - - // iterate each stream descriptor and create alert datasource for each - for (StreamDesc streamDesc : streamDescToInstall) { - // only take care of Kafka sink - if (streamDesc.getSinkConfig() instanceof KafkaStreamSinkConfig) { - KafkaStreamSinkConfig kafkaCfg = (KafkaStreamSinkConfig) streamDesc.getSinkConfig(); - Kafka2TupleMetadata datasource = new Kafka2TupleMetadata(); - datasource.setType("KAFKA"); - datasource.setName(streamDesc.getStreamId()); - datasource.setTopic(kafkaCfg.getTopicId()); - datasource.setSchemeCls(JsonScheme.class.getCanonicalName()); - datasource.setProperties(new HashMap<>()); - - KafkaStreamSourceConfig streamSourceConfig = (KafkaStreamSourceConfig) streamDesc.getSourceConfig(); - if (streamSourceConfig != null) { - Map properties = datasource.getProperties(); - properties.put(AlertConstants.KAFKA_BROKER_ZK_BASE_PATH, streamSourceConfig.getBrokerZkPath()); - properties.put(AlertConstants.KAFKA_BROKER_ZK_QUORUM, streamSourceConfig.getBrokerZkQuorum()); - } - - Tuple2StreamMetadata tuple2Stream = new Tuple2StreamMetadata(); - Properties prop = new Properties(); - prop.put(JsonStringStreamNameSelector.USER_PROVIDED_STREAM_NAME_PROPERTY, streamDesc.getStreamId()); - tuple2Stream.setStreamNameSelectorProp(prop); - tuple2Stream.setTimestampColumn("timestamp"); - tuple2Stream.setStreamNameSelectorCls(JsonStringStreamNameSelector.class.getCanonicalName()); - datasource.setCodec(tuple2Stream); - alertMetadataService.addDataSource(datasource); - - StreamDefinition sd = streamDesc.getSchema(); - sd.setDataSource(streamDesc.getStreamId()); - sd.setStreamSource(metadata.getAppId()); - alertMetadataService.createStream(streamDesc.getSchema()); - } - } - } - - public void doUninstall() { - // we should remove alert data source and stream definition while we do uninstall - if (metadata.getStreams() == null) { - return; - } - // iterate each stream descriptor and create alert datasource for each - for (StreamDesc streamDesc : metadata.getStreams()) { - alertMetadataService.removeDataSource(streamDesc.getStreamId()); - alertMetadataService.removeStream(streamDesc.getStreamId()); - } - } - - public void doStart() { - if (metadata.getStreams() == null) { - processStreams(); - } - this.runtime.start(this.application, this.effectiveConfig); - } - - @SuppressWarnings("unchecked") - public void doStop() { - this.runtime.stop(this.application, this.effectiveConfig); - } - - public ApplicationEntity.Status getStatus() { - return this.runtime.status(this.application, this.effectiveConfig); - } - - public ApplicationEntity getMetadata() { - return metadata; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationEmailService.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationEmailService.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationEmailService.java deleted file mode 100644 index 7498748..0000000 --- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationEmailService.java +++ /dev/null @@ -1,104 +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.app.service; - -import com.typesafe.config.Config; -import org.apache.eagle.common.mail.AbstractEmailService; -import org.apache.eagle.common.mail.AlertEmailConstants; -import org.apache.eagle.common.mail.AlertEmailContext; -import org.apache.eagle.common.mail.AlertEmailSender; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.Map; - -import static org.apache.eagle.common.mail.AlertEmailConstants.EAGLE_APPLICATION_EMAIL_SERVICE; - -public class ApplicationEmailService extends AbstractEmailService { - private static final Logger LOG = LoggerFactory.getLogger(ApplicationEmailService.class); - private String appConfPath; - private Config config; - - public ApplicationEmailService(Config config, String appConfPath) { - super(config.getConfig(EAGLE_APPLICATION_EMAIL_SERVICE)); - this.appConfPath = appConfPath; - this.config = config; - } - - public boolean onAlert(Map alertData) { - return super.onAlert(buildEmailContext(), alertData); - } - - private String buildDefaultSender() { - String hostname = ""; - try { - hostname = InetAddress.getLocalHost().getHostName(); - if (!hostname.endsWith(".com")) { - //avoid invalid host exception - hostname += ".com"; - } - } catch (UnknownHostException e) { - LOG.warn("UnknownHostException when get local hostname"); - } - return System.getProperty("user.name") + "@" + hostname; - } - - public AlertEmailContext buildEmailContext() { - return buildEmailContext(null); - } - - public AlertEmailContext buildEmailContext(String mailSubject) { - AlertEmailContext mailProps = new AlertEmailContext(); - Config appConfig = config.getConfig(appConfPath); - String tplFileName = appConfig.getString(AlertEmailConstants.TEMPLATE); - if (tplFileName == null || tplFileName.equals("")) { - tplFileName = "ALERT_INLINED_TEMPLATE.vm"; - } - String subject; - if (mailSubject != null) { - subject = mailSubject; - } else { - subject = appConfig.getString(AlertEmailConstants.SUBJECT); - } - String sender; - if (!appConfig.hasPath(AlertEmailConstants.SENDER)) { - sender = buildDefaultSender(); - } else { - sender = appConfig.getString(AlertEmailConstants.SENDER); - } - if (!appConfig.hasPath(AlertEmailConstants.RECIPIENTS)) { - throw new IllegalArgumentException("email recipients is null or unset"); - } - if (appConfig.hasPath(AlertEmailConstants.CC_RECIPIENTS)) { - mailProps.setCc(appConfig.getString(AlertEmailConstants.CC_RECIPIENTS)); - } - String recipients = appConfig.getString(AlertEmailConstants.RECIPIENTS); - mailProps.setSubject(subject); - mailProps.setRecipients(recipients); - mailProps.setSender(sender); - mailProps.setVelocityTplFile(tplFileName); - return mailProps; - } - - @Override - protected Logger getLogger() { - return LOG; - } -} http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationHealthCheckPublisher.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationHealthCheckPublisher.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationHealthCheckPublisher.java deleted file mode 100644 index 8e91029..0000000 --- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationHealthCheckPublisher.java +++ /dev/null @@ -1,26 +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.app.service; - -import com.codahale.metrics.health.HealthCheck; - -import java.util.Map; - -public interface ApplicationHealthCheckPublisher { - void onUnHealthApplication(String type, Map results); -} http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationHealthCheckService.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationHealthCheckService.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationHealthCheckService.java deleted file mode 100644 index 21ae6b1..0000000 --- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationHealthCheckService.java +++ /dev/null @@ -1,30 +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.app.service; - -import com.google.common.util.concurrent.AbstractScheduledService; -import io.dropwizard.setup.Environment; -import org.apache.eagle.metadata.model.ApplicationEntity; - -public abstract class ApplicationHealthCheckService extends AbstractScheduledService { - public abstract void init(Environment environment); - - public abstract void register(ApplicationEntity appEntity); - - public abstract void unregister(ApplicationEntity appEntity); -} http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationListener.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationListener.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationListener.java deleted file mode 100644 index 4a7f0c6..0000000 --- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationListener.java +++ /dev/null @@ -1,32 +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.app.service; - -import org.apache.eagle.app.ApplicationLifecycle; -import org.apache.eagle.metadata.model.ApplicationEntity; - -/** - * Application Lifecycle/Management Listener (Guice Aware). - * Currently only listen on application lifecycle , may extend to more later. - */ -public interface ApplicationListener extends ApplicationLifecycle { - /** - * @param applicationEntity ApplicationEntity. - */ - void init(ApplicationEntity applicationEntity); -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationManagementService.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationManagementService.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationManagementService.java deleted file mode 100644 index e5a7e0c..0000000 --- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationManagementService.java +++ /dev/null @@ -1,64 +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.app.service; - -import org.apache.eagle.metadata.exceptions.ApplicationWrongStatusException; -import org.apache.eagle.metadata.exceptions.EntityNotFoundException; -import org.apache.eagle.metadata.model.ApplicationEntity; - -public interface ApplicationManagementService { - /** - * Install application. - * - * @param operation - * @return - */ - ApplicationEntity install(ApplicationOperations.InstallOperation operation) throws EntityNotFoundException; - - /** - * Uninstall application. - * - * @param operation - * @return - */ - ApplicationEntity uninstall(ApplicationOperations.UninstallOperation operation) throws ApplicationWrongStatusException; - - /** - * Start application. - * - * @param operation - * @return - */ - ApplicationEntity start(ApplicationOperations.StartOperation operation) throws ApplicationWrongStatusException; - - /** - * Stop application. - * - * @param operation - * @return - */ - ApplicationEntity stop(ApplicationOperations.StopOperation operation) throws ApplicationWrongStatusException; - - /** - * get application status. - * - * @param operation - * @return - */ - ApplicationEntity.Status getStatus(ApplicationOperations.CheckStatusOperation operation) throws EntityNotFoundException; - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationOperations.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationOperations.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationOperations.java deleted file mode 100644 index 52e25be..0000000 --- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationOperations.java +++ /dev/null @@ -1,302 +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.app.service; - -import org.apache.eagle.metadata.model.ApplicationEntity; - -import java.io.Serializable; -import java.util.Map; - -public final class ApplicationOperations { - interface Operation extends Serializable { - String getType(); - } - - private static final String INSTALL = "INSTALL"; - private static final String UNINSTALL = "UNINSTALL"; - private static final String START = "START"; - private static final String STOP = "STOP"; - - public static class InstallOperation implements Operation { - private String siteId; - private String appType; - private ApplicationEntity.Mode mode = ApplicationEntity.Mode.LOCAL; - private String jarPath; - private Map configuration; - - public InstallOperation() { - } - - public InstallOperation(String siteId, String appType) { - this.setSiteId(siteId); - this.setAppType(appType); - } - - public InstallOperation(String siteId, String appType, ApplicationEntity.Mode mode) { - this.setSiteId(siteId); - this.setAppType(appType); - this.setMode(mode); - } - - public InstallOperation(String siteId, String appType, ApplicationEntity.Mode mode, String jarPath) { - this.setSiteId(siteId); - this.setAppType(appType); - this.setMode(mode); - this.setJarPath(jarPath); - } - - public InstallOperation(String siteId, String appType, ApplicationEntity.Mode mode, String jarPath, Map configuration) { - this.setSiteId(siteId); - this.setAppType(appType); - this.setMode(mode); - this.setJarPath(jarPath); - this.setConfiguration(configuration); - } - - public String getSiteId() { - return siteId; - } - - public void setSiteId(String siteId) { - this.siteId = siteId; - } - - public String getAppType() { - return appType; - } - - public void setAppType(String appType) { - this.appType = appType; - } - - public Map getConfiguration() { - return configuration; - } - - public void setConfiguration(Map configuration) { - this.configuration = configuration; - } - - public ApplicationEntity.Mode getMode() { - return mode; - } - - public void setMode(ApplicationEntity.Mode mode) { - this.mode = mode; - } - - public String getJarPath() { - return jarPath; - } - - public void setJarPath(String jarPath) { - this.jarPath = jarPath; - } - - @Override - public String getType() { - return INSTALL; - } - } - - public static class UpdateOperation implements Operation { - private ApplicationEntity.Mode mode = ApplicationEntity.Mode.LOCAL; - private String jarPath; - private Map configuration; - - public Map getConfiguration() { - return configuration; - } - - public void setConfiguration(Map configuration) { - this.configuration = configuration; - } - - public ApplicationEntity.Mode getMode() { - return mode; - } - - public void setMode(ApplicationEntity.Mode mode) { - this.mode = mode; - } - - public String getJarPath() { - return jarPath; - } - - public void setJarPath(String jarPath) { - this.jarPath = jarPath; - } - - @Override - public String getType() { - return INSTALL; - } - } - - public static class UninstallOperation implements Operation { - private String uuid; - private String appId; - - public UninstallOperation() { - } - - public UninstallOperation(String uuid) { - this.setUuid(uuid); - } - - public UninstallOperation(String uuid, String appId) { - this.setUuid(uuid); - this.setAppId(appId); - } - - public String getUuid() { - return uuid; - } - - public void setUuid(String uuid) { - this.uuid = uuid; - } - - public String getAppId() { - return appId; - } - - public void setAppId(String appId) { - this.appId = appId; - } - - @Override - public String getType() { - return UNINSTALL; - } - } - - public static class StartOperation implements Operation { - private String uuid; - private String appId; - - public StartOperation() { - } - - public StartOperation(String uuid) { - this.setUuid(uuid); - } - - public StartOperation(String uuid, String appId) { - this.setUuid(uuid); - this.setAppId(appId); - } - - public String getUuid() { - return uuid; - } - - public void setUuid(String uuid) { - this.uuid = uuid; - } - - public String getAppId() { - return appId; - } - - public void setAppId(String appId) { - this.appId = appId; - } - - @Override - public String getType() { - return START; - } - } - - public static class StopOperation implements Operation { - private String uuid; - private String appId; - - public StopOperation() { - } - - public StopOperation(String uuid) { - this.setUuid(uuid); - } - - public StopOperation(String uuid, String appId) { - this.setUuid(uuid); - this.setAppId(appId); - } - - public String getUuid() { - return uuid; - } - - public void setUuid(String uuid) { - this.uuid = uuid; - } - - public String getAppId() { - return appId; - } - - public void setAppId(String appId) { - this.appId = appId; - } - - @Override - public String getType() { - return STOP; - } - } - - public static class CheckStatusOperation implements Operation { - private String uuid; - private String appId; - - public CheckStatusOperation() { - } - - public CheckStatusOperation(String uuid) { - this.setUuid(uuid); - } - - public CheckStatusOperation(String uuid, String appId) { - this.setUuid(uuid); - this.setAppId(appId); - } - - public String getUuid() { - return uuid; - } - - public void setUuid(String uuid) { - this.uuid = uuid; - } - - public String getAppId() { - return appId; - } - - public void setAppId(String appId) { - this.appId = appId; - } - - @Override - public String getType() { - return START; - } - } -} http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationProviderLoader.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationProviderLoader.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationProviderLoader.java deleted file mode 100644 index 11e5dca..0000000 --- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationProviderLoader.java +++ /dev/null @@ -1,79 +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.app.service; - -import org.apache.eagle.app.service.impl.ApplicationProviderConfigLoader; -import org.apache.eagle.app.service.impl.ApplicationProviderSPILoader; -import org.apache.eagle.app.spi.ApplicationProvider; -import com.typesafe.config.Config; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -public abstract class ApplicationProviderLoader { - private final Config config; - private final Map providers; - private static final Logger LOG = LoggerFactory.getLogger(ApplicationProviderLoader.class); - - public ApplicationProviderLoader(Config config) { - this.config = config; - this.providers = new HashMap<>(); - } - - public abstract void load(); - - protected Config getConfig() { - return config; - } - - protected void registerProvider(ApplicationProvider provider) { - if (providers.containsKey(provider.getApplicationDesc().getType())) { - throw new RuntimeException("Duplicated APPLICATION_TYPE: " + provider.getApplicationDesc().getType() - + ", was already registered by provider: " + providers.get(provider.getApplicationDesc().getType())); - } - providers.put(provider.getApplicationDesc().getType(), provider); - LOG.info("Initialized application provider: {}", provider); - } - - public Collection getProviders() { - return providers.values(); - } - - public ApplicationProvider getApplicationProviderByType(String type) { - if (providers.containsKey(type)) { - return providers.get(type); - } else { - throw new IllegalArgumentException("Illegal Application Type: " + type); - } - } - - public void reset() { - providers.clear(); - } - - public static String getDefaultAppProviderLoader() { - if (ApplicationProviderConfigLoader - .appProviderConfExists(ApplicationProviderConfigLoader.DEFAULT_APPLICATIONS_CONFIG_FILE)) { - return ApplicationProviderConfigLoader.class.getCanonicalName(); - } else { - return ApplicationProviderSPILoader.class.getCanonicalName(); - } - } -} http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationProviderService.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationProviderService.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationProviderService.java deleted file mode 100644 index 71e7eb0..0000000 --- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationProviderService.java +++ /dev/null @@ -1,32 +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.app.service; - -import org.apache.eagle.app.Application; -import org.apache.eagle.app.spi.ApplicationProvider; -import org.apache.eagle.metadata.service.ApplicationDescService; - -import java.util.Collection; - -public interface ApplicationProviderService extends ApplicationDescService { - void reload(); - - Collection getProviders(); - - ApplicationProvider getApplicationProviderByType(String type); -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationHealthCheckBase.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationHealthCheckBase.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationHealthCheckBase.java deleted file mode 100644 index c607fe7..0000000 --- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationHealthCheckBase.java +++ /dev/null @@ -1,72 +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.app.service.impl; - -import com.codahale.metrics.health.HealthCheck; -import com.google.inject.Inject; -import com.typesafe.config.Config; -import org.apache.eagle.metadata.model.ApplicationEntity; -import org.apache.eagle.metadata.service.ApplicationEntityService; - -import java.io.PrintWriter; -import java.io.StringWriter; - -public abstract class ApplicationHealthCheckBase extends HealthCheck { - private static final String APP_ID_PATH = "appId"; - protected static final long DEFAULT_MAX_DELAY_TIME = 2 * 60 * 60 * 1000L; - protected static final String MAX_DELAY_TIME_KEY = "application.maxDelayTime"; - - protected Config config; - - @Inject - private ApplicationEntityService applicationEntityService; - - protected ApplicationHealthCheckBase(Config config) { - this.config = config; - } - - protected ApplicationEntity.Status getApplicationStatus() { - ApplicationEntity applicationEntity = applicationEntityService.getByUUIDOrAppId(null, config.getString(APP_ID_PATH)); - return applicationEntity.getStatus(); - } - - protected String printMessages(String ... messages) { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw, true); - for (int i = 0; i < messages.length; i++) { - pw.println(messages[i]); - } - return sw.getBuffer().toString(); - } - - protected String formatMillSeconds(long millseconds) { - millseconds = millseconds / 1000; - String result; - if (millseconds <= 60) { - result = millseconds + " seconds"; - } else if (millseconds > 60 && millseconds <= 3600) { - result = String.format("%.2f minutes", millseconds * 1.0 / 60); - } else if (millseconds > 3600 && millseconds <= 3600 * 24) { - result = String.format("%.2f hours", millseconds * 1.0 / 3600); - } else { - result = String.format("%.2f days", millseconds * 1.0 / 3600 / 24); - } - - return result; - } -} http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationHealthCheckEmailPublisher.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationHealthCheckEmailPublisher.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationHealthCheckEmailPublisher.java deleted file mode 100644 index 9c700bf..0000000 --- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationHealthCheckEmailPublisher.java +++ /dev/null @@ -1,165 +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.app.service.impl; - -import com.codahale.metrics.health.HealthCheck; -import com.typesafe.config.Config; -import org.apache.eagle.alert.engine.publisher.email.AlertEmailConstants; -import org.apache.eagle.alert.engine.publisher.email.EagleMailClient; -import org.apache.eagle.app.service.ApplicationHealthCheckPublisher; -import org.apache.velocity.VelocityContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.net.InetAddress; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -public class ApplicationHealthCheckEmailPublisher implements ApplicationHealthCheckPublisher { - private static final Logger LOG = LoggerFactory.getLogger(ApplicationHealthCheckEmailPublisher.class); - private static final int MAX_RETRY_COUNT = 3; - private static final String CONF_MAIL_RECIPIENTS = "mail.smtp.recipients"; - private static final String CONF_MAIL_SENDER = "mail.smtp.sender"; - private static final String CONF_MAIL_SUBJECT = "mail.smtp.subject"; - private static final String CONF_MAIL_CC = "mail.smtp.cc"; - private static final String CONF_MAIL_TEMPLATE = "mail.smtp.template"; - private static final String UNHEALTHY_CONTEXT = "unHealthyContext"; - private static final Integer HEALTH_CHECK_PORT = 9091; - private static final String SERVICE_HOST = "host"; - private static final String SERVICE_PORT = "port"; - - private Config config; - - public ApplicationHealthCheckEmailPublisher(Config config) { - this.config = config; - } - - @Override - public void onUnHealthApplication(String type, Map results) { - if (results.size() == 0) { - return; - } - Properties properties = parseMailClientConfig(); - if (properties == null) { - return; - } - - int count = 0; - boolean success = false; - while (count++ < MAX_RETRY_COUNT && !success) { - LOG.info("Sending email, tried: " + count + ", max: " + MAX_RETRY_COUNT); - try { - String recipients = config.getString(CONF_MAIL_RECIPIENTS); - if (recipients == null || recipients.equals("")) { - LOG.error("Recipients is null, skip sending emails "); - return; - } - - final VelocityContext context = new VelocityContext(); - Map appMsgs = new HashMap<>(); - int unhealthyCount = 0; - int healthyCount = 0; - for (String appId : results.keySet()) { - appMsgs.put(appId, results.get(appId).getMessage()); - if (!results.get(appId).isHealthy()) { - unhealthyCount++; - } else { - healthyCount++; - } - } - Map unHealthyContext = new HashMap<>(); - unHealthyContext.put("appMsgs", appMsgs); - unHealthyContext.put("appMgmtUrl", "http://" + config.getString(SERVICE_HOST) + ":" + config.getInt(SERVICE_PORT) + "/#/integration/site"); - unHealthyContext.put("healthCheckUrl", "http://" + config.getString(SERVICE_HOST) + ":" + HEALTH_CHECK_PORT + "/healthcheck"); - context.put(UNHEALTHY_CONTEXT, unHealthyContext); - - String subject = ""; - if (healthyCount > 0) { - subject += healthyCount + " healthy app(s)"; - } - if (unhealthyCount > 0) { - if (!subject.isEmpty()) { - subject += ", "; - } - subject += unhealthyCount + " unhealthy app(s)"; - } - subject = config.getString(CONF_MAIL_SUBJECT) + ": " + subject; - EagleMailClient client = new EagleMailClient(properties); - String hostname = InetAddress.getLocalHost().getHostName(); - if (!hostname.endsWith(".com")) { - //avoid invalid host exception - hostname += ".com"; - } - success = client.send( - System.getProperty("user.name") + "@" + hostname, - recipients, - config.hasPath(CONF_MAIL_CC) ? config.getString(CONF_MAIL_CC) : null, - type + subject, - config.getString(CONF_MAIL_TEMPLATE), - context, - null); - - LOG.info("Success of sending email: " + success); - if (!success && count < MAX_RETRY_COUNT) { - LOG.info("Sleep for a while before retrying"); - Thread.sleep(10 * 1000); - } - } catch (Exception e) { - LOG.warn("Sending mail exception", e); - } - } - if (success) { - LOG.info("Successfully send unhealthy email"); - } else { - LOG.warn("Fail sending unhealthy email after tries {} times", MAX_RETRY_COUNT); - } - } - - private Properties parseMailClientConfig() { - Properties props = new Properties(); - - String mailHost = config.getString(AlertEmailConstants.CONF_MAIL_HOST); - int mailPort = config.getInt(AlertEmailConstants.CONF_MAIL_PORT); - if (mailHost == null || mailPort == 0 || mailHost.isEmpty()) { - LOG.warn("SMTP server is unset, will exit"); - return null; - } - props.put(AlertEmailConstants.CONF_MAIL_HOST, mailHost); - props.put(AlertEmailConstants.CONF_MAIL_PORT, mailPort); - - Boolean smtpAuth = config.hasPath(AlertEmailConstants.CONF_MAIL_AUTH) && config.getBoolean(AlertEmailConstants.CONF_MAIL_AUTH); - props.put(AlertEmailConstants.CONF_MAIL_AUTH, smtpAuth); - if (smtpAuth) { - props.put(AlertEmailConstants.CONF_AUTH_USER, config.getString(AlertEmailConstants.CONF_AUTH_USER)); - props.put(AlertEmailConstants.CONF_AUTH_PASSWORD, config.getString(AlertEmailConstants.CONF_AUTH_PASSWORD)); - } - - String smtpConn = config.hasPath(AlertEmailConstants.CONF_MAIL_CONN) ? config.getString(AlertEmailConstants.CONF_MAIL_CONN) : AlertEmailConstants.CONN_PLAINTEXT; - if (smtpConn.equalsIgnoreCase(AlertEmailConstants.CONN_TLS)) { - props.put("mail.smtp.starttls.enable", "true"); - } - if (smtpConn.equalsIgnoreCase(AlertEmailConstants.CONN_SSL)) { - props.put("mail.smtp.socketFactory.port", "465"); - props.put("mail.smtp.socketFactory.class", - "javax.net.ssl.SSLSocketFactory"); - } - props.put(AlertEmailConstants.CONF_MAIL_DEBUG, config.hasPath(AlertEmailConstants.CONF_MAIL_DEBUG) && config.getBoolean(AlertEmailConstants.CONF_MAIL_DEBUG)); - return props; - } -} http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationHealthCheckServiceImpl.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationHealthCheckServiceImpl.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationHealthCheckServiceImpl.java deleted file mode 100644 index 8403d55..0000000 --- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationHealthCheckServiceImpl.java +++ /dev/null @@ -1,217 +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.app.service.impl; - -import com.codahale.metrics.health.HealthCheck; -import com.google.inject.Inject; -import com.google.inject.Injector; -import com.typesafe.config.Config; -import com.typesafe.config.ConfigFactory; -import io.dropwizard.setup.Environment; -import org.apache.eagle.app.service.ApplicationHealthCheckPublisher; -import org.apache.eagle.app.service.ApplicationHealthCheckService; -import org.apache.eagle.app.service.ApplicationProviderService; -import org.apache.eagle.app.spi.ApplicationProvider; -import org.apache.eagle.metadata.model.ApplicationEntity; -import org.apache.eagle.metadata.service.ApplicationEntityService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.lang.reflect.Constructor; -import java.util.*; -import java.util.concurrent.TimeUnit; - -public class ApplicationHealthCheckServiceImpl extends ApplicationHealthCheckService { - private static final Logger LOG = LoggerFactory.getLogger(ApplicationHealthCheckServiceImpl.class); - - private final ApplicationProviderService applicationProviderService; - private final ApplicationEntityService applicationEntityService; - private ApplicationHealthCheckPublisher applicationHealthCheckPublisher; - private final Config config; - private Environment environment; - private Map> appHealthChecks = new HashMap<>(); - private final Object lock = new Object(); - private int initialDelay = 10; - private int period = 300; - - public static final String HEALTH_CHECK_PATH = "application.healthCheck"; - private static final String HEALTH_INITIAL_DELAY_PATH = "application.healthCheck.initialDelay"; - private static final String HEALTH_PERIOD_PATH = "application.healthCheck.period"; - private static final String HEALTH_PUBLISHER_PATH = "application.healthCheck.publisher"; - private static final String HEALTH_PUBLISHER_IMPL_PATH = "application.healthCheck.publisher.publisherImpl"; - private static final String HEALTH_CHECK_DAILY_SEND_HOUR_PATH = "application.healthCheck.publisher.dailySendHour"; - private static final String SERVICE_PATH = "service"; - private static final String TIMEZONE_PATH = "service.timezone"; - private static final String HEALTHY = "OK"; - private static final String DAILY_TYPE = "[DAILY] - "; - private static final String ERROR_TYPE = "[ERROR] - "; - - private boolean hasSendDaily = false; - - private TimeZone timeZone; - - @Inject - private Injector currentInjector; - - @Inject - public ApplicationHealthCheckServiceImpl(ApplicationProviderService applicationProviderService, - ApplicationEntityService applicationEntityService, - Config config) { - this.applicationProviderService = applicationProviderService; - this.applicationEntityService = applicationEntityService; - this.config = config; - if (this.config.hasPath(HEALTH_INITIAL_DELAY_PATH)) { - this.initialDelay = this.config.getInt(HEALTH_INITIAL_DELAY_PATH); - } - - if (this.config.hasPath(HEALTH_PERIOD_PATH)) { - this.period = this.config.getInt(HEALTH_PERIOD_PATH); - } - - this.applicationHealthCheckPublisher = null; - if (this.config.hasPath(HEALTH_PUBLISHER_PATH)) { - try { - String className = this.config.getString(HEALTH_PUBLISHER_IMPL_PATH); - Class clz; - clz = Thread.currentThread().getContextClassLoader().loadClass(className); - if (ApplicationHealthCheckPublisher.class.isAssignableFrom(clz)) { - Constructor cotr = clz.getConstructor(Config.class); - this.applicationHealthCheckPublisher = (ApplicationHealthCheckPublisher)cotr.newInstance( - this.config.getConfig(HEALTH_PUBLISHER_PATH).withFallback(this.config.getConfig(SERVICE_PATH))); - } - } catch (Exception e) { - LOG.warn("Exception found when create ApplicationHealthCheckPublisher instance {}", e.getCause()); - } - } - } - - @Override - public void init(Environment environment) { - this.environment = environment; - registerAll(); - this.timeZone = TimeZone.getTimeZone(config.getString(TIMEZONE_PATH)); - } - - private void registerAll() { - Collection applicationEntities = applicationEntityService.findAll(); - applicationEntities.forEach(this::register); - } - - @Override - public void register(ApplicationEntity appEntity) { - if (environment == null) { - LOG.warn("Environment is null, can not register"); - return; - } - ApplicationProvider appProvider = applicationProviderService.getApplicationProviderByType(appEntity.getDescriptor().getType()); - Optional applicationHealthCheck = appProvider.getManagedHealthCheck( - ConfigFactory.parseMap(appEntity.getContext()) - .withFallback(config) - .withFallback(ConfigFactory.parseMap(appEntity.getConfiguration())) - ); - - if (!applicationHealthCheck.isPresent()) { - LOG.warn("Application {} does not implement HealthCheck", appEntity.getAppId()); - return; - } - this.environment.healthChecks().register(appEntity.getAppId(), applicationHealthCheck.get()); - currentInjector.injectMembers(applicationHealthCheck.get()); - synchronized (lock) { - if (!appHealthChecks.containsKey(appEntity.getAppId())) { - appHealthChecks.put(appEntity.getAppId(), applicationHealthCheck); - LOG.info("Successfully register health check for {}", appEntity.getAppId()); - } - } - } - - @Override - public void unregister(ApplicationEntity appEntity) { - if (environment == null) { - LOG.warn("Environment is null, can not unregister"); - return; - } - this.environment.healthChecks().unregister(appEntity.getAppId()); - synchronized (lock) { - appHealthChecks.remove(appEntity.getAppId()); - } - LOG.info("Successfully unregister health check for {}", appEntity.getAppId()); - } - - @Override - protected void runOneIteration() throws Exception { - LOG.info("Starting ApplicationHealthCheckService"); - registerAll(); - - boolean isDaily = false; - int dailySendHour = config.getInt(HEALTH_CHECK_DAILY_SEND_HOUR_PATH); - - GregorianCalendar cal = new GregorianCalendar(timeZone); - if (cal.get(Calendar.HOUR_OF_DAY) == dailySendHour && !hasSendDaily) { - isDaily = true; - } - - if (cal.get(Calendar.HOUR_OF_DAY) != dailySendHour) { - hasSendDaily = false; - } - Map copyAppHealthChecks = new HashMap<>(); - synchronized (lock) { - for (String appId : appHealthChecks.keySet()) { - copyAppHealthChecks.put(appId, appHealthChecks.get(appId).get()); - } - } - - Map results = new HashMap<>(); - for (String appId : copyAppHealthChecks.keySet()) { - HealthCheck.Result result = copyAppHealthChecks.get(appId).execute(); - if (result.isHealthy()) { - if (isDaily) { - if (result.getMessage() == null || result.getMessage().isEmpty()) { - results.put(appId, HealthCheck.Result.healthy(HEALTHY)); - } else { - results.put(appId, result); - } - } - LOG.info("Application {} is healthy", appId); - } else { - results.put(appId, result); - LOG.warn("Application {} is not healthy, {}", appId, result.getMessage(), result.getError()); - } - } - - String type = ERROR_TYPE; - if (this.applicationHealthCheckPublisher != null) { - try { - if (isDaily) { - type = DAILY_TYPE; - } - this.applicationHealthCheckPublisher.onUnHealthApplication(type, results); - if (isDaily) { - hasSendDaily = true; - } - } catch (Exception e) { - LOG.warn("Failed to send email for unhealthy applications", e); - } - } - - } - - @Override - protected Scheduler scheduler() { - return Scheduler.newFixedRateSchedule(initialDelay, period, TimeUnit.SECONDS); - } -} http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationManagementServiceImpl.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationManagementServiceImpl.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationManagementServiceImpl.java deleted file mode 100644 index cd97496..0000000 --- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationManagementServiceImpl.java +++ /dev/null @@ -1,260 +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.app.service.impl; - -import com.google.common.base.Preconditions; -import com.google.inject.Inject; -import com.google.inject.Injector; -import com.google.inject.Singleton; -import com.typesafe.config.Config; -import org.apache.eagle.alert.metadata.IMetadataDao; -import org.apache.eagle.app.Application; -import org.apache.eagle.app.service.*; -import org.apache.eagle.app.spi.ApplicationProvider; -import org.apache.eagle.metadata.exceptions.ApplicationWrongStatusException; -import org.apache.eagle.metadata.exceptions.EntityNotFoundException; -import org.apache.eagle.metadata.model.*; -import org.apache.eagle.metadata.service.ApplicationEntityService; -import org.apache.eagle.metadata.service.SiteEntityService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@Singleton -public class ApplicationManagementServiceImpl implements ApplicationManagementService { - private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationManagementServiceImpl.class); - - private final SiteEntityService siteEntityService; - private final ApplicationProviderService applicationProviderService; - private final ApplicationEntityService applicationEntityService; - private final IMetadataDao alertMetadataService; - private final Config config; - private final ApplicationHealthCheckService applicationHealthCheckService; - - @Inject private Injector currentInjector; - - @Inject - public ApplicationManagementServiceImpl( - Config config, - SiteEntityService siteEntityService, - ApplicationProviderService applicationProviderService, - ApplicationEntityService applicationEntityService, - IMetadataDao alertMetadataService, - ApplicationHealthCheckService applicationHealthCheckService) { - this.config = config; - this.siteEntityService = siteEntityService; - this.applicationProviderService = applicationProviderService; - this.applicationEntityService = applicationEntityService; - this.alertMetadataService = alertMetadataService; - this.applicationHealthCheckService = applicationHealthCheckService; - } - - @Override - public ApplicationEntity install(ApplicationOperations.InstallOperation operation) throws EntityNotFoundException { - Preconditions.checkNotNull(operation.getSiteId(), "siteId is null"); - Preconditions.checkNotNull(operation.getAppType(), "appType is null"); - SiteEntity siteEntity = siteEntityService.getBySiteId(operation.getSiteId()); - Preconditions.checkNotNull(siteEntity, "Site with ID: " + operation.getSiteId() + " is not found"); - ApplicationDesc appDesc = applicationProviderService.getApplicationDescByType(operation.getAppType()); - Preconditions.checkNotNull("Application with TYPE: " + operation.getAppType() + " is not found"); - ApplicationEntity applicationEntity = new ApplicationEntity(); - applicationEntity.setDescriptor(appDesc); - applicationEntity.setSite(siteEntity); - applicationEntity.setMode(operation.getMode()); - applicationEntity.setJarPath(operation.getJarPath() == null ? appDesc.getJarPath() : operation.getJarPath()); - applicationEntity.ensureDefault(); - - // Calculate application config based on: - // - // 1) default values in metadata.xml. - // 2) user's config value override default configurations. - // 3) fill runtime information, for example siteId, mode, appId in ApplicationOperationContext. - - Map appConfig = new HashMap<>(); - ApplicationProvider provider = applicationProviderService.getApplicationProviderByType(operation.getAppType()); - - ApplicationDesc applicationDesc = provider.getApplicationDesc(); - - if (applicationDesc.getConfiguration() != null) { - List propertyList = provider.getApplicationDesc().getConfiguration().getProperties(); - for (Property p : propertyList) { - appConfig.put(p.getName(), p.getValue()); - } - if (operation.getConfiguration() != null) { - appConfig.putAll(operation.getConfiguration()); - } - } - applicationEntity.setConfiguration(appConfig); - - applicationEntity.getContext().put("siteId", siteEntity.getSiteId()); - applicationEntity.getContext().put("appId", applicationEntity.getAppId()); - - // Validate Dependency - validateDependingApplicationInstalled(applicationEntity); - - ApplicationProvider applicationProvider = applicationProviderService.getApplicationProviderByType(applicationEntity.getDescriptor().getType()); - - // DoInstall - ApplicationAction applicationAction = new ApplicationAction(applicationProvider.getApplication(), applicationEntity, config, alertMetadataService); - applicationAction.doInstall(); - - applicationHealthCheckService.register(applicationEntity); - - // UpdateMetadata - ApplicationEntity result = applicationEntityService.create(applicationEntity); - - // AfterInstall Callback - applicationProvider.getApplicationListener().ifPresent((listener) -> { - currentInjector.injectMembers(listener); - listener.init(result); - listener.afterInstall(); - }); - - return result; - } - - private void validateDependingApplicationInstalled(ApplicationEntity applicationEntity) { - if (applicationEntity.getDescriptor().getDependencies() != null) { - for (ApplicationDependency dependency : applicationEntity.getDescriptor().getDependencies()) { - if (dependency.isRequired() && applicationEntityService.getBySiteIdAndAppType(applicationEntity.getSite().getSiteId(), dependency.getType()) == null) { - throw new IllegalStateException("Required dependency " + dependency.toString() + " of " + applicationEntity.getDescriptor().getType() + " was not installed"); - } - } - } - } - - @Override - public ApplicationEntity uninstall(ApplicationOperations.UninstallOperation operation) throws ApplicationWrongStatusException { - ApplicationEntity appEntity = applicationEntityService.getByUUIDOrAppId(operation.getUuid(), operation.getAppId()); - ApplicationProvider appProvider = applicationProviderService.getApplicationProviderByType(appEntity.getDescriptor().getType()); - - ApplicationAction appAction = new ApplicationAction(appProvider.getApplication(), appEntity, config, alertMetadataService); - ApplicationEntity.Status currentStatus = appEntity.getStatus(); - try { - if (currentStatus == ApplicationEntity.Status.INITIALIZED || currentStatus == ApplicationEntity.Status.STOPPED) { - // AfterUninstall Callback - appAction.doUninstall(); - appProvider.getApplicationListener().ifPresent((listener) -> { - currentInjector.injectMembers(listener); - listener.init(appEntity); - listener.afterUninstall(); - }); - - applicationHealthCheckService.unregister(appEntity); - - return applicationEntityService.delete(appEntity); - } else { - throw new ApplicationWrongStatusException("App: " + appEntity.getAppId() + " status is " + currentStatus + ", uninstall operation is not allowed"); - } - } catch (Throwable throwable) { - LOGGER.error(throwable.getMessage(), throwable); - throw throwable; - } - } - - @Override - public ApplicationEntity start(ApplicationOperations.StartOperation operation) throws ApplicationWrongStatusException { - ApplicationEntity appEntity = applicationEntityService.getByUUIDOrAppId(operation.getUuid(), operation.getAppId()); - ApplicationProvider appProvider = applicationProviderService.getApplicationProviderByType(appEntity.getDescriptor().getType()); - Application application = appProvider.getApplication(); - Preconditions.checkArgument(application.isExecutable(), "Application is not executable"); - - ApplicationEntity.Status currentStatus = appEntity.getStatus(); - try { - if (currentStatus == ApplicationEntity.Status.INITIALIZED || currentStatus == ApplicationEntity.Status.STOPPED) { - ApplicationAction applicationAction = new ApplicationAction(application, appEntity, config, alertMetadataService); - // AfterInstall Callback - appProvider.getApplicationListener().ifPresent((listener) -> { - currentInjector.injectMembers(listener); - listener.init(appEntity); - listener.beforeStart(); - }); - applicationAction.doStart(); - - //TODO: Only when topology submitted successfully can the state change to STARTING - applicationEntityService.delete(appEntity); - appEntity.setStatus(ApplicationEntity.Status.STARTING); - return applicationEntityService.create(appEntity); - } else { - throw new ApplicationWrongStatusException("App: " + appEntity.getAppId() + " status is " + currentStatus + " start operation is not allowed"); - } - } catch (ApplicationWrongStatusException e) { - LOGGER.error(e.getMessage(), e); - throw e; - } catch (Exception e) { - LOGGER.error("Failed to start app " + appEntity.getAppId(), e); - throw e; - } catch (Throwable throwable) { - LOGGER.error(throwable.getMessage(), throwable); - throw throwable; - } - } - - @Override - public ApplicationEntity stop(ApplicationOperations.StopOperation operation) throws ApplicationWrongStatusException { - ApplicationEntity applicationEntity = applicationEntityService.getByUUIDOrAppId(operation.getUuid(), operation.getAppId()); - ApplicationProvider appProvider = applicationProviderService.getApplicationProviderByType(applicationEntity.getDescriptor().getType()); - Application application = appProvider.getApplication(); - Preconditions.checkArgument(application.isExecutable(), "Application is not executable"); - - ApplicationAction applicationAction = new ApplicationAction(application, applicationEntity, config, alertMetadataService); - ApplicationEntity.Status currentStatus = applicationEntity.getStatus(); - try { - if (currentStatus == ApplicationEntity.Status.RUNNING) { - applicationAction.doStop(); - appProvider.getApplicationListener().ifPresent((listener) -> { - currentInjector.injectMembers(listener); - listener.init(applicationEntity); - listener.afterStop(); - }); - //stop -> directly killed - applicationEntityService.delete(applicationEntity); - applicationEntity.setStatus(ApplicationEntity.Status.STOPPING); - return applicationEntityService.create(applicationEntity); - } else { - throw new ApplicationWrongStatusException("App: " + applicationEntity.getAppId() + " status is " + currentStatus + ", stop operation is not allowed."); - } - } catch (ApplicationWrongStatusException e) { - LOGGER.error(e.getMessage(), e); - throw e; - } catch (RuntimeException e) { - LOGGER.error("Failed to stop app " + applicationEntity.getAppId(), e); - throw e; - } catch (Throwable throwable) { - LOGGER.error(throwable.getMessage(), throwable); - throw throwable; - } - } - - @Override - public ApplicationEntity.Status getStatus(ApplicationOperations.CheckStatusOperation operation) { - try { - ApplicationEntity applicationEntity = applicationEntityService.getByUUIDOrAppId(operation.getUuid(), operation.getAppId()); - Application application = applicationProviderService.getApplicationProviderByType(applicationEntity.getDescriptor().getType()).getApplication(); - Preconditions.checkArgument(application.isExecutable(), "Application is not executable"); - - ApplicationAction applicationAction = new ApplicationAction(application, applicationEntity, config, alertMetadataService); - return applicationAction.getStatus(); - } catch (IllegalArgumentException e) { - LOGGER.error("application id not exist", e); - throw e; - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationProviderConfigLoader.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationProviderConfigLoader.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationProviderConfigLoader.java deleted file mode 100644 index 1455922..0000000 --- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationProviderConfigLoader.java +++ /dev/null @@ -1,139 +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.app.service.impl; - -import org.apache.eagle.app.config.ApplicationProviderConfig; -import org.apache.eagle.app.config.ApplicationProvidersConfig; -import org.apache.eagle.app.service.ApplicationProviderLoader; -import org.apache.eagle.app.spi.ApplicationProvider; -import com.google.common.base.Preconditions; -import com.typesafe.config.Config; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.io.InputStream; -import java.util.List; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.Unmarshaller; - -/** - * @deprecated unstable implementation. - */ -@Deprecated -public class ApplicationProviderConfigLoader extends ApplicationProviderLoader { - public static final String DEFAULT_APPLICATIONS_CONFIG_FILE = "providers.xml"; - private static final String APPLICATIONS_CONFIG_PROPS_KEY = "application.provider.config"; - private static final Logger LOG = LoggerFactory.getLogger(ApplicationProviderConfigLoader.class); - - public ApplicationProviderConfigLoader(Config config) { - super(config); - } - - @Override - public void load() { - List applicationProviderConfigs = loadProvidersFromProvidersConf(); - int totalCount = applicationProviderConfigs.size(); - int loadedCount = 0; - int failedCount = 0; - for (ApplicationProviderConfig providerConfig : applicationProviderConfigs) { - try { - initializeProvider(providerConfig); - loadedCount++; - } catch (Throwable ex) { - LOG.warn("Failed to initialized {}, ignored", providerConfig, ex); - failedCount++; - } - } - LOG.info("Loaded {} app providers (total: {}, failed: {})", loadedCount, totalCount, failedCount); - } - - public static boolean appProviderConfExists(String applicationConfFile) { - InputStream is = ApplicationProviderConfigLoader.class.getResourceAsStream(applicationConfFile); - if (is == null) { - is = ApplicationProviderConfigLoader.class.getResourceAsStream("/" + applicationConfFile); - } - - if (is != null) { - try { - return true; - } finally { - try { - is.close(); - } catch (IOException e) { - LOG.debug(e.getMessage()); - } - } - } else { - return false; - } - } - - private void initializeProvider(ApplicationProviderConfig providerConfig) throws ClassNotFoundException, IllegalAccessException, InstantiationException { - LOG.info("Loading application provider {} from {}", providerConfig.getClassName(), providerConfig.getJarPath()); - String providerClassName = providerConfig.getClassName(); - if (providerClassName == null) { - throw new RuntimeException("provider.classname is null: " + providerConfig); - } - if (providerConfig.getJarPath() == null) { - throw new RuntimeException("provider.jarpath is null: " + providerConfig); - } - - Class providerClass = Class.forName(providerClassName); - - if (!ApplicationProvider.class.isAssignableFrom(providerClass)) { - throw new RuntimeException("providerClassName is not implementation of " + ApplicationProvider.class.getCanonicalName()); - } - ApplicationProvider provider = (ApplicationProvider) providerClass.newInstance(); - Preconditions.checkNotNull(provider.getApplicationDesc(), "appDesc is null"); - Preconditions.checkNotNull(provider.getApplicationDesc().getType(), "type is null"); - registerProvider(provider); - } - - private List loadProvidersFromProvidersConf() { - String providerConfigFile = DEFAULT_APPLICATIONS_CONFIG_FILE; - if (getConfig().hasPath(APPLICATIONS_CONFIG_PROPS_KEY)) { - providerConfigFile = getConfig().getString(APPLICATIONS_CONFIG_PROPS_KEY); - LOG.info("Set {} = {}", APPLICATIONS_CONFIG_PROPS_KEY, providerConfigFile); - } - InputStream is = null; - try { - JAXBContext jc = JAXBContext.newInstance(ApplicationProvidersConfig.class); - final Unmarshaller unmarshaller = jc.createUnmarshaller(); - is = ApplicationProviderConfigLoader.class.getResourceAsStream(providerConfigFile); - if (is == null) { - is = ApplicationProviderConfigLoader.class.getResourceAsStream("/" + providerConfigFile); - } - if (is == null) { - LOG.error("Application provider configuration {} is not found", providerConfigFile); - } - Preconditions.checkNotNull(is, providerConfigFile + " is not found"); - return ((ApplicationProvidersConfig) unmarshaller.unmarshal(is)).getProviders(); - } catch (Exception ex) { - LOG.error("Failed to load application provider configuration: {}", providerConfigFile, ex); - throw new RuntimeException("Failed to load application provider configuration: " + providerConfigFile, ex); - } finally { - if (is != null) { - try { - is.close(); - } catch (IOException e) { - LOG.error(e.getMessage(), e); - } - } - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/eagle/blob/6fd95d5c/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationProviderSPILoader.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationProviderSPILoader.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationProviderSPILoader.java deleted file mode 100644 index aa62251..0000000 --- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationProviderSPILoader.java +++ /dev/null @@ -1,97 +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.app.service.impl; - -import com.typesafe.config.Config; -import org.apache.eagle.app.config.ApplicationProviderConfig; -import org.apache.eagle.app.service.ApplicationProviderLoader; -import org.apache.eagle.app.spi.ApplicationProvider; -import org.apache.eagle.app.utils.DynamicJarPathFinder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ServiceLoader; -import java.util.function.Function; - -/** - * Load Application KafkaStreamMessaging with SPI, by default from current class loader. - */ -public class ApplicationProviderSPILoader extends ApplicationProviderLoader { - private final String appProviderExtDir; - private static final Logger LOG = LoggerFactory.getLogger(ApplicationProviderSPILoader.class); - private static final String APPLICATIONS_DIR_PROPS_KEY = "application.provider.dir"; - - public ApplicationProviderSPILoader(Config config) { - super(config); - if (config.hasPath(APPLICATIONS_DIR_PROPS_KEY)) { - this.appProviderExtDir = config.getString(APPLICATIONS_DIR_PROPS_KEY); - LOG.warn("Using {}: {}", APPLICATIONS_DIR_PROPS_KEY, this.appProviderExtDir); - } else { - this.appProviderExtDir = null; - } - } - - @Override - public void load() { - if (appProviderExtDir != null) { - LOG.warn("Loading application providers from class loader of jars in {}", appProviderExtDir); - File loc = new File(appProviderExtDir); - File[] jarFiles = loc.listFiles(file -> file.getPath().toLowerCase().endsWith(".jar")); - if (jarFiles != null) { - for (File jarFile : jarFiles) { - try { - URL jarFileUrl = jarFile.toURI().toURL(); - LOG.debug("Loading ApplicationProvider from jar: {}", jarFileUrl.toString()); - URLClassLoader jarFileClassLoader = new URLClassLoader(new URL[] {jarFileUrl}); - loadProviderFromClassLoader(jarFileClassLoader, (applicationProviderConfig) -> jarFileUrl.getPath()); - } catch (Exception e) { - LOG.warn("Failed to load application provider from jar {}", jarFile, e); - } - } - } - } else { - LOG.warn("Loading application providers from context class loader"); - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - loadProviderFromClassLoader(classLoader, (applicationProvider) -> DynamicJarPathFinder.findPath(applicationProvider.getClass())); - } - } - - private void loadProviderFromClassLoader(ClassLoader jarFileClassLoader, Function jarFileSupplier) { - ServiceLoader serviceLoader = ServiceLoader.load(ApplicationProvider.class); - try { - for (ApplicationProvider applicationProvider : serviceLoader) { - ApplicationProviderConfig providerConfig = new ApplicationProviderConfig(); - providerConfig.setClassName(applicationProvider.getClass().getCanonicalName()); - providerConfig.setJarPath(jarFileSupplier.apply(applicationProvider)); - applicationProvider.getApplicationDesc().setExecutable(applicationProvider.getApplication().isExecutable()); - registerProvider(applicationProvider); - LOG.warn("Loaded {}:{} ({}) from {}", - applicationProvider.getApplicationDesc().getType(), - applicationProvider.getApplicationDesc().getVersion(), - applicationProvider.getApplicationDesc().getName(), - providerConfig.getJarPath() - ); - } - } catch (Throwable ex) { - LOG.error("Failed to register application provider", ex); - throw new IllegalStateException(ex); - } - } -}