Repository: incubator-eagle
Updated Branches:
  refs/heads/master 6385174ed -> fa4334e1e


[EAGLE-705] streams is null when call /rest/apps/ api

Author: wujinhu <wujinhu...@126.com>

Closes #588 from wujinhu/EAGLE-705.


Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/fa4334e1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/fa4334e1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/fa4334e1

Branch: refs/heads/master
Commit: fa4334e1ef5371efed6a37f771aff40bda186eee
Parents: 6385174
Author: wujinhu <wujinhu...@126.com>
Authored: Tue Nov 1 11:54:17 2016 +0800
Committer: wujinhu <wujinhu...@126.com>
Committed: Tue Nov 1 11:54:17 2016 +0800

----------------------------------------------------------------------
 .../metadata/resource/MetadataResource.java     |  5 +++
 .../eagle/app/resource/ApplicationResource.java |  1 -
 .../ApplicationEntityServiceJDBCImpl.java       | 34 ++++++++++++++++++++
 3 files changed, 39 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/fa4334e1/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata-service/src/main/java/org/apache/eagle/service/metadata/resource/MetadataResource.java
----------------------------------------------------------------------
diff --git 
a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata-service/src/main/java/org/apache/eagle/service/metadata/resource/MetadataResource.java
 
b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata-service/src/main/java/org/apache/eagle/service/metadata/resource/MetadataResource.java
index 49a9611..45ffa2d 100644
--- 
a/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata-service/src/main/java/org/apache/eagle/service/metadata/resource/MetadataResource.java
+++ 
b/eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata-service/src/main/java/org/apache/eagle/service/metadata/resource/MetadataResource.java
@@ -249,6 +249,11 @@ public class MetadataResource {
     @POST
     public OpResult addPublishmentsToPolicy(@PathParam("policyId") String 
policyId, List<String> publishmentIds) {
         OpResult result = new OpResult();
+        if (publishmentIds == null || publishmentIds.size() == 0) {
+            result.code = OpResult.FAILURE;
+            result.message = "Failed to add policy, there is no publisher in 
it";
+            return result;
+        }
         try {
             getPolicyByID(policyId);
             Map<String,Publishment> publishmentMap = new HashMap<>();

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/fa4334e1/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/resource/ApplicationResource.java
----------------------------------------------------------------------
diff --git 
a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/resource/ApplicationResource.java
 
b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/resource/ApplicationResource.java
index e634598..f304768 100644
--- 
a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/resource/ApplicationResource.java
+++ 
b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/resource/ApplicationResource.java
@@ -16,7 +16,6 @@
  */
 package org.apache.eagle.app.resource;
 
-
 import org.apache.eagle.app.service.ApplicationManagementService;
 import org.apache.eagle.app.service.ApplicationOperations;
 import org.apache.eagle.app.service.ApplicationProviderService;

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/fa4334e1/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/service/ApplicationEntityServiceJDBCImpl.java
----------------------------------------------------------------------
diff --git 
a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/service/ApplicationEntityServiceJDBCImpl.java
 
b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/service/ApplicationEntityServiceJDBCImpl.java
index 96b33bf..df0eebf 100644
--- 
a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/service/ApplicationEntityServiceJDBCImpl.java
+++ 
b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/service/ApplicationEntityServiceJDBCImpl.java
@@ -18,15 +18,23 @@
 package org.apache.eagle.metadata.store.jdbc.service;
 
 
+import com.typesafe.config.Config;
+import com.typesafe.config.ConfigFactory;
 import org.apache.commons.lang.StringUtils;
+import org.apache.eagle.alert.engine.coordinator.StreamDefinition;
+import org.apache.eagle.app.environment.ExecutionRuntime;
+import org.apache.eagle.app.environment.ExecutionRuntimeManager;
 import org.apache.eagle.app.service.ApplicationProviderService;
 import org.apache.eagle.metadata.model.ApplicationEntity;
+import org.apache.eagle.metadata.model.StreamDesc;
+import org.apache.eagle.metadata.model.StreamSinkConfig;
 import org.apache.eagle.metadata.service.ApplicationEntityService;
 import org.apache.eagle.metadata.store.jdbc.JDBCMetadataQueryService;
 import 
org.apache.eagle.metadata.store.jdbc.service.orm.ApplicationEntityToRelation;
 import 
org.apache.eagle.metadata.store.jdbc.service.orm.RelationToApplicationEntity;
 
 import com.google.inject.Singleton;
+import org.apache.eagle.metadata.utils.StreamIdConversions;
 import org.json.simple.JSONObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -34,7 +42,9 @@ import org.slf4j.LoggerFactory;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.List;
+import java.util.stream.Collectors;
 
 import javax.inject.Inject;
 
@@ -55,6 +65,8 @@ public class ApplicationEntityServiceJDBCImpl implements 
ApplicationEntityServic
     JDBCMetadataQueryService queryService;
     @Inject
     ApplicationProviderService applicationProviderService;
+    @Inject
+    Config config;
 
     @Override
     public Collection<ApplicationEntity> findBySiteId(String siteId) {
@@ -187,6 +199,28 @@ public class ApplicationEntityServiceJDBCImpl implements 
ApplicationEntityServic
     private void fillApplicationDesc(List<ApplicationEntity> entities) {
         for (ApplicationEntity entity : entities) {
             
entity.setDescriptor(applicationProviderService.getApplicationDescByType(entity.getDescriptor().getType()));
+            if (entity.getDescriptor().getStreams() == null) {
+                continue;
+            }
+            List<StreamDesc> streamDescToInstall = 
entity.getDescriptor().getStreams().stream().map((streamDefinition -> {
+                StreamDefinition copied = streamDefinition.copy();
+                copied.setSiteId(entity.getSite().getSiteId());
+                
copied.setStreamId(StreamIdConversions.formatSiteStreamId(entity.getSite().getSiteId(),
 copied.getStreamId()));
+                Config effectiveConfig = ConfigFactory.parseMap(new 
HashMap<>(entity.getConfiguration()))
+                        
.withFallback(config).withFallback(ConfigFactory.parseMap(entity.getContext()));
+
+                ExecutionRuntime runtime = 
ExecutionRuntimeManager.getInstance().getRuntime(
+                        
applicationProviderService.getApplicationProviderByType(entity.getDescriptor().getType()).getApplication().getEnvironmentType(),
 config);
+                StreamSinkConfig streamSinkConfig = runtime.environment()
+                        
.streamSink().getSinkConfig(StreamIdConversions.parseStreamTypeId(copied.getSiteId(),
 copied.getStreamId()), effectiveConfig);
+                StreamDesc streamDesc = new StreamDesc();
+                streamDesc.setSchema(copied);
+                streamDesc.setSink(streamSinkConfig);
+                streamDesc.setStreamId(copied.getStreamId());
+                streamDesc.getSchema().setDataSource(entity.getAppId());
+                return streamDesc;
+            })).collect(Collectors.toList());
+            entity.setStreams(streamDescToInstall);
         }
     }
 

Reply via email to