Repository: incubator-eagle
Updated Branches:
  refs/heads/master 279bc01cd -> 6823410fc


[EAGLE-613] Support modify ApplicationEntity through POST /rest/apps/{UUID}/

Support modify ApplicationEntity through
~~~
POST /rest/apps/{UUID}/
~~~

* REQUEST BODY* (UpdateOperation)
~~~
{
    "configuration": {
        "spout.stormKafkaUseSameZkQuorumWithKafkaBroker": "true",
        "metadataService.port": "9090",
        "spout.stormKafkaEagleConsumer": "eagle_consumer",
        "topology.numOfSpoutTasks": "1",
        "jarPath": 
"incubator-eagle/eagle-core/eagle-alert-parent/eagle-alert-app/target/classes/org/apache/eagle/alert/app/AlertUnitTopologyApp.class",
        "topology.numOfRouterBolts": "4",
        "topology.numOfAlertBolts": "10",
        "zkConfig.zkRoot": "/alert",
        "zkConfig.zkQuorum": "localhost:2181",
        "mode": "LOCAL",
        "metadataService.context": "/rest",
        "metadataService.host": "localhost",
        "topology.messageTimeoutSecs": "3600",
        "spout.kafkaBrokerZkQuorum": "localhost:2181",
        "appId": "ALERTUNITTOPOLOGYAPP_SANDBOX",
        "topology.numOfTotalWorkers": "2",
        "siteId": "sandbox",
        "topology.numOfPublishTasks": "1",
        "spout.stormKafkaTransactionZkPath": "/consumers",
        "spout.kafkaBrokerZkBasePath": "/brokers"
    },
    "mode": "CLUSTER",
    "jarPath": 
"incubator-eagle/eagle-core/eagle-alert-parent/eagle-alert-app/target/classes/org/apache/eagle/alert/app/AlertUnitTopologyApp.class"
}
~~~

Author: Hao Chen <h...@apache.org>

Closes #495 from haoch/EAGLE-613.


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

Branch: refs/heads/master
Commit: 6823410fc85fe13d9295125d9093754d38e4f0ac
Parents: 279bc01
Author: Hao Chen <h...@apache.org>
Authored: Wed Oct 12 18:01:08 2016 +0800
Committer: Hao Chen <h...@apache.org>
Committed: Wed Oct 12 18:01:08 2016 +0800

----------------------------------------------------------------------
 .../eagle/app/resource/ApplicationResource.java | 14 ++++++++
 .../app/service/ApplicationOperations.java      | 35 ++++++++++++++++++++
 .../eagle/metadata/model/ApplicationEntity.java | 11 ++++++
 .../service/ApplicationEntityService.java       |  1 +
 .../ApplicationEntityServiceMemoryImpl.java     |  9 +++++
 .../ApplicationEntityServiceJDBCImpl.java       |  9 ++++-
 6 files changed, 78 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/6823410f/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 717f7c0..b493b2b 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
@@ -91,6 +91,20 @@ public class ApplicationResource {
     }
 
     @POST
+    @Path("/{appUuid}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public RESTResponse<ApplicationEntity> 
updateApplicationEntity(@PathParam("appUuid") String appUuid, 
ApplicationOperations.UpdateOperation updateOperation) {
+        return RESTResponse.async(() -> {
+            ApplicationEntity applicationEntity = new ApplicationEntity();
+            applicationEntity.setUuid(appUuid);
+            applicationEntity.setJarPath(updateOperation.getJarPath());
+            applicationEntity.setMode(updateOperation.getMode());
+            
applicationEntity.setConfiguration(updateOperation.getConfiguration());
+            return entityService.update(applicationEntity);
+        }).get();
+    }
+
+    @POST
     @Path("/status")
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces(MediaType.APPLICATION_JSON)

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/6823410f/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
index 36c08b8..52e25be 100644
--- 
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
@@ -113,6 +113,41 @@ public final class ApplicationOperations {
         }
     }
 
+    public static class UpdateOperation implements Operation {
+        private ApplicationEntity.Mode mode = ApplicationEntity.Mode.LOCAL;
+        private String jarPath;
+        private Map<String, Object> configuration;
+
+        public Map<String, Object> getConfiguration() {
+            return configuration;
+        }
+
+        public void setConfiguration(Map<String, Object> 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;

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/6823410f/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/model/ApplicationEntity.java
----------------------------------------------------------------------
diff --git 
a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/model/ApplicationEntity.java
 
b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/model/ApplicationEntity.java
index c6d01f4..952b5a8 100644
--- 
a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/model/ApplicationEntity.java
+++ 
b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/model/ApplicationEntity.java
@@ -180,6 +180,17 @@ public class ApplicationEntity extends PersistenceEntity {
         }
     }
 
+    /**
+     * Update mutable fields from another ApplicationEntity
+     */
+    public void updateMutable(ApplicationEntity entityToUpdate){
+        this.ensureDefault();
+
+        this.setJarPath(entityToUpdate.getJarPath());
+        this.setMode(entityToUpdate.getMode());
+        this.setConfiguration(entityToUpdate.getConfiguration());
+    }
+
     public static enum Mode {
         LOCAL("LOCAL"),
         CLUSTER("CLUSTER");

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/6823410f/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/service/ApplicationEntityService.java
----------------------------------------------------------------------
diff --git 
a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/service/ApplicationEntityService.java
 
b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/service/ApplicationEntityService.java
index 9e05f9b..69dc921 100644
--- 
a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/service/ApplicationEntityService.java
+++ 
b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/service/ApplicationEntityService.java
@@ -27,4 +27,5 @@ public interface ApplicationEntityService extends 
PersistenceService<Application
     ApplicationEntity getBySiteIdAndAppType(String siteId,String appType);
     ApplicationEntity getByUUIDOrAppId(String uuid,String appId);
     ApplicationEntity delete(ApplicationEntity applicationEntity);
+    ApplicationEntity update(ApplicationEntity entity);
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/6823410f/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/service/memory/ApplicationEntityServiceMemoryImpl.java
----------------------------------------------------------------------
diff --git 
a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/service/memory/ApplicationEntityServiceMemoryImpl.java
 
b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/service/memory/ApplicationEntityServiceMemoryImpl.java
index c6c2b31..9151ba2 100644
--- 
a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/service/memory/ApplicationEntityServiceMemoryImpl.java
+++ 
b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/service/memory/ApplicationEntityServiceMemoryImpl.java
@@ -16,6 +16,7 @@
  */
 package org.apache.eagle.metadata.service.memory;
 
+import com.google.common.base.Preconditions;
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 import org.apache.eagle.metadata.model.ApplicationEntity;
@@ -102,4 +103,12 @@ public class ApplicationEntityServiceMemoryImpl implements 
ApplicationEntityServ
         ApplicationEntity entity = 
getByUUIDOrAppId(applicationEntity.getUuid(), applicationEntity.getAppId());
         return applicationEntityMap.remove(entity.getUuid());
     }
+
+    @Override
+    public ApplicationEntity update(ApplicationEntity entity) {
+        Preconditions.checkNotNull(entity.getUuid(),"UUID");
+        ApplicationEntity origin = getByUUID(entity.getUuid());
+        origin.updateMutable(entity);
+        return origin;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/6823410f/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 8dbc446..20932b1 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
@@ -116,6 +116,14 @@ public class ApplicationEntityServiceJDBCImpl implements 
ApplicationEntityServic
         return entity;
     }
 
+    /**
+     * TODO: UPDATE ApplicationEntity through JDBC is not supported yet
+     */
+    @Override
+    public ApplicationEntity update(ApplicationEntity entity) {
+        throw new UnsupportedOperationException("UPDATE ApplicationEntity 
through JDBC is not supported yet");
+    }
+
     @Override
     public Collection<ApplicationEntity> findAll() {
         List<ApplicationEntity> results = new ArrayList<>();
@@ -144,7 +152,6 @@ public class ApplicationEntityServiceJDBCImpl implements 
ApplicationEntityServic
 
     @Override
     public ApplicationEntity create(ApplicationEntity entity) {
-
         entity.ensureDefault();
         if (getBySiteIdAndAppType(entity.getSite().getSiteId(), 
entity.getDescriptor().getType()) != null) {
             throw new IllegalArgumentException("Duplicated appId: " + 
entity.getAppId());

Reply via email to