eagle-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h..@apache.org
Subject incubator-eagle git commit: [EAGLE-403] Add CRUD for site resource
Date Fri, 29 Jul 2016 11:02:18 GMT
Repository: incubator-eagle
Updated Branches:
  refs/heads/develop b75367832 -> 0feba43d4


[EAGLE-403] Add CRUD for site resource

Author: Hao Chen <hao@apache.org>

Closes #286 from haoch/EAGLE-403-SITE.


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

Branch: refs/heads/develop
Commit: 0feba43d4bb93b431f8eccc41ab001859793cecd
Parents: b753678
Author: Hao Chen <hao@apache.org>
Authored: Fri Jul 29 19:02:00 2016 +0800
Committer: Hao Chen <hao@apache.org>
Committed: Fri Jul 29 19:02:00 2016 +0800

----------------------------------------------------------------------
 .../eagle/app/resource/ApplicationResource.java | 26 +++++-----
 .../service/ApplicationManagementService.java   |  3 +-
 .../impl/ApplicationManagementServiceImpl.java  |  3 +-
 .../ApplicationNotFoundException.java           | 31 ++++++++++++
 .../exceptions/EntityNotFoundException.java     | 31 ++++++++++++
 .../IllegalApplicationTypeException.java        | 20 ++++++++
 .../persistence/PersistenceService.java         |  4 +-
 .../eagle/metadata/resource/RESTResponse.java   | 37 +++++++++++----
 .../eagle/metadata/resource/SiteResource.java   | 26 ++++++++--
 .../metadata/service/SiteEntityService.java     |  6 ++-
 .../SiteEntityEntityServiceMemoryImpl.java      | 50 ++++++++++++++------
 .../eagle/server/RESTExceptionMapper.java       | 28 +----------
 12 files changed, 194 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0feba43d/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 185a1d5..dad9f66 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
@@ -1,4 +1,4 @@
-/**
+/*
  * 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.
@@ -64,10 +64,10 @@ public class ApplicationResource {
     @Path("/providers/reload")
     @Produces(MediaType.APPLICATION_JSON)
     public RESTResponse<Collection<ApplicationDesc>> reloadApplicationDescs(){
-        return RESTResponse.<Collection<ApplicationDesc>>async((builder)->
{
+        return RESTResponse.<Collection<ApplicationDesc>>async((response)->
{
             providerService.reload();
-            builder.message("Successfully reload application providers");
-            builder.data(providerService.getApplicationDescs());
+            response.message("Successfully reload application providers");
+            response.data(providerService.getApplicationDescs());
         }).get();
     }
 
@@ -104,10 +104,10 @@ public class ApplicationResource {
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces(MediaType.APPLICATION_JSON)
     public RESTResponse<ApplicationEntity> installApplication(ApplicationOperations.InstallOperation
operation){
-        return RESTResponse.<ApplicationEntity>async((builder)-> {
+        return RESTResponse.<ApplicationEntity>async((response)-> {
             ApplicationEntity entity = applicationManagementService.install(operation);
-            builder.message("Successfully installed application "+operation.getAppType()+"
onto site "+operation.getSiteId());
-            builder.data(entity);
+            response.message("Successfully installed application "+operation.getAppType()+"
onto site "+operation.getSiteId());
+            response.data(entity);
         }).get();
     }
 
@@ -126,9 +126,9 @@ public class ApplicationResource {
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces(MediaType.APPLICATION_JSON)
     public RESTResponse<Void> uninstallApplication(ApplicationOperations.UninstallOperation
operation){
-        return RESTResponse.<Void>async((builder)-> {
+        return RESTResponse.<Void>async((response)-> {
             ApplicationEntity entity = applicationManagementService.uninstall(operation);
-            builder.success(true).message("Successfully uninstalled application "+entity.getUuid());
+            response.success(true).message("Successfully uninstalled application "+entity.getUuid());
         }).get();
     }
 
@@ -146,9 +146,9 @@ public class ApplicationResource {
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces(MediaType.APPLICATION_JSON)
     public RESTResponse<Void> startApplication(ApplicationOperations.StartOperation
operation){
-        return RESTResponse.<Void>async((builder)-> {
+        return RESTResponse.<Void>async((response)-> {
             ApplicationEntity entity = applicationManagementService.start(operation);
-            builder.success(true).message("Successfully started application "+entity.getUuid());
+            response.success(true).message("Successfully started application "+entity.getUuid());
         }).get();
     }
 
@@ -166,9 +166,9 @@ public class ApplicationResource {
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces(MediaType.APPLICATION_JSON)
     public RESTResponse<Void> stopApplication(ApplicationOperations.StopOperation operation){
-        return RESTResponse.<Void>async((builder)-> {
+        return RESTResponse.<Void>async((response)-> {
             ApplicationEntity entity = applicationManagementService.stop(operation);
-            builder.success(true).message("Successfully stopped application "+entity.getUuid());
+            response.success(true).message("Successfully stopped application "+entity.getUuid());
         }).get();
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0feba43d/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
index 30ae0b9..82c441a 100644
--- 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
@@ -16,6 +16,7 @@
  */
 package org.apache.eagle.app.service;
 
+import org.apache.eagle.metadata.exceptions.EntityNotFoundException;
 import org.apache.eagle.metadata.model.ApplicationEntity;
 
 public interface ApplicationManagementService {
@@ -24,7 +25,7 @@ public interface ApplicationManagementService {
      * @param operation
      * @return
      */
-    ApplicationEntity install(ApplicationOperations.InstallOperation operation);
+    ApplicationEntity install(ApplicationOperations.InstallOperation operation) throws EntityNotFoundException;
 
     /**
      *

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0feba43d/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
index 9e34459..f681b6d 100644
--- 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
@@ -24,6 +24,7 @@ import org.apache.eagle.app.ApplicationContext;
 import org.apache.eagle.app.service.ApplicationOperations;
 import org.apache.eagle.app.service.ApplicationManagementService;
 import org.apache.eagle.app.service.ApplicationProviderService;
+import org.apache.eagle.metadata.exceptions.EntityNotFoundException;
 import org.apache.eagle.metadata.model.ApplicationDesc;
 import org.apache.eagle.metadata.model.ApplicationEntity;
 import org.apache.eagle.metadata.model.SiteEntity;
@@ -52,7 +53,7 @@ public class ApplicationManagementServiceImpl implements ApplicationManagementSe
         this.applicationEntityService = applicationEntityService;
     }
 
-    public ApplicationEntity install(ApplicationOperations.InstallOperation operation) {
+    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());

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0feba43d/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/exceptions/ApplicationNotFoundException.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/exceptions/ApplicationNotFoundException.java
b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/exceptions/ApplicationNotFoundException.java
new file mode 100644
index 0000000..2b986c4
--- /dev/null
+++ b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/exceptions/ApplicationNotFoundException.java
@@ -0,0 +1,31 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.metadata.exceptions;
+
+public class ApplicationNotFoundException extends Exception {
+    public ApplicationNotFoundException(String message) {
+        super(message);
+    }
+
+    public ApplicationNotFoundException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public ApplicationNotFoundException(Throwable cause) {
+        super(cause);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0feba43d/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/exceptions/EntityNotFoundException.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/exceptions/EntityNotFoundException.java
b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/exceptions/EntityNotFoundException.java
new file mode 100644
index 0000000..990d77c
--- /dev/null
+++ b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/exceptions/EntityNotFoundException.java
@@ -0,0 +1,31 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.metadata.exceptions;
+
+public class EntityNotFoundException extends Exception{
+    public EntityNotFoundException(Throwable cause) {
+        super(cause);
+    }
+
+    public EntityNotFoundException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public EntityNotFoundException(String message) {
+        super(message);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0feba43d/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/exceptions/IllegalApplicationTypeException.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/exceptions/IllegalApplicationTypeException.java
b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/exceptions/IllegalApplicationTypeException.java
new file mode 100644
index 0000000..b9efb58
--- /dev/null
+++ b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/exceptions/IllegalApplicationTypeException.java
@@ -0,0 +1,20 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.metadata.exceptions;
+
+public class IllegalApplicationTypeException {
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0feba43d/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/persistence/PersistenceService.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/persistence/PersistenceService.java
b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/persistence/PersistenceService.java
index d525936..bde8298 100644
--- a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/persistence/PersistenceService.java
+++ b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/persistence/PersistenceService.java
@@ -16,10 +16,12 @@
  */
 package org.apache.eagle.metadata.persistence;
 
+import org.apache.eagle.metadata.exceptions.EntityNotFoundException;
+
 import java.util.Collection;
 
 public interface PersistenceService<T extends PersistenceEntity> {
     Collection<T> findAll();
-    T getByUUID(String uuid);
+    T getByUUID(String uuid) throws EntityNotFoundException;
     T create(T entity);
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0feba43d/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/RESTResponse.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/RESTResponse.java
b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/RESTResponse.java
index 4431c8c..1c9d112 100644
--- a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/RESTResponse.java
+++ b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/RESTResponse.java
@@ -22,6 +22,7 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Response;
 import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
 import java.util.function.Consumer;
 import java.util.function.Supplier;
 
@@ -32,6 +33,17 @@ public class RESTResponse<T>{
     private String exception;
     private T data;
 
+    public RESTResponse(){}
+
+    public RESTResponse(Throwable throwable){
+        if(throwable.getMessage() == null || throwable.getMessage().isEmpty()) {
+            this.setMessage(throwable.getMessage());
+        }else{
+            this.setMessage(ExceptionUtils.getMessage(throwable));
+        }
+        this.setException(ExceptionUtils.getStackTrace(throwable));
+    }
+
     public T getData() {
         return data;
     }
@@ -96,6 +108,7 @@ public class RESTResponse<T>{
     public static class RestResponseBuilder<E>{
         private RESTResponse current = new RESTResponse();
         private Response.Status status = Response.Status.OK;
+        private CompletableFuture future = null;
 
         public RestResponseBuilder<E> success(boolean success){
             this.current.setSuccess(success);
@@ -119,6 +132,13 @@ public class RESTResponse<T>{
 
         public RestResponseBuilder<E> exception(Throwable exception){
             this.current.setThrowable(exception);
+            if(this.current.getMessage() == null){
+                if(exception.getMessage() ==null || exception.getMessage().isEmpty()){
+                    this.current.setMessage(ExceptionUtils.getMessage(exception));
+                }else{
+                    this.current.setMessage(exception.getMessage());
+                }
+            }
             return this;
         }
 
@@ -127,7 +147,7 @@ public class RESTResponse<T>{
                 this.success(true).status(Response.Status.OK);
                 func.accept(this);
             } catch (Exception ex){
-                this.success(false).data(null).status(Response.Status.INTERNAL_SERVER_ERROR).message(ex.getMessage());
+                this.success(false).data(null).status(Response.Status.BAD_REQUEST).exception(ex);
                 raiseWebAppException(ex);
             }
             return this;
@@ -137,7 +157,7 @@ public class RESTResponse<T>{
             try {
                 this.success(true).status(Response.Status.OK).data(func.get());
             } catch (Throwable ex){
-                this.success(false).status(Response.Status.INTERNAL_SERVER_ERROR).message(ex.getMessage());
+                this.success(false).status(Response.Status.BAD_REQUEST).exception(ex);
                 raiseWebAppException(ex);
             }
             return this;
@@ -148,7 +168,7 @@ public class RESTResponse<T>{
                 try {
                     this.status(Response.Status.OK).success(true).data(func.get());
                 } catch (Throwable e) {
-                    this.success(false).status(Response.Status.INTERNAL_SERVER_ERROR).message(e.getMessage()).exception(e);
+                    this.success(false).status(Response.Status.BAD_REQUEST).exception(e);
                     raiseWebAppException(e);
                 }
             });
@@ -162,9 +182,10 @@ public class RESTResponse<T>{
             } catch (InterruptedException ex) {
                 Thread.currentThread().interrupt();
                 future.cancel(true);
-                this.success(false).status(Response.Status.INTERNAL_SERVER_ERROR).message(ex.getMessage()).exception(ex);
-            } catch (Throwable ex) {
-                this.success(false).status(Response.Status.INTERNAL_SERVER_ERROR).message(ex.getMessage()).exception(ex);
+                this.success(false).status(Response.Status.BAD_REQUEST).exception(ex.getCause());
+                raiseWebAppException(ex);
+            } catch (ExecutionException ex) {
+                this.success(false).status(Response.Status.BAD_REQUEST).exception(ex.getCause());
                 raiseWebAppException(ex);
             }
         }
@@ -179,7 +200,7 @@ public class RESTResponse<T>{
                     func.accept(this);
                     this.success(true);
                 } catch (Throwable ex) {
-                    this.success(false).status(Response.Status.INTERNAL_SERVER_ERROR).message(ex.getMessage()).exception(ex);
+                    this.success(false).status(Response.Status.BAD_REQUEST).exception(ex);
                     raiseWebAppException(ex);
                 }
             });
@@ -191,7 +212,7 @@ public class RESTResponse<T>{
             try {
                 func.accept(this);
             } catch (Throwable ex) {
-                this.success(false).status(Response.Status.INTERNAL_SERVER_ERROR).message(ex.getMessage()).exception(ex);
+                this.success(false).status(Response.Status.BAD_REQUEST).exception(ex);
                 raiseWebAppException(ex);
             }
             return this;

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0feba43d/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/SiteResource.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/SiteResource.java
b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/SiteResource.java
index ec683b7..972cda1 100644
--- a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/SiteResource.java
+++ b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/SiteResource.java
@@ -25,8 +25,6 @@ import javax.ws.rs.*;
 import javax.ws.rs.core.MediaType;
 import java.util.Collection;
 
-import static org.apache.eagle.metadata.resource.RESTResponse.async;
-
 @Path("/sites")
 @Singleton
 public class SiteResource {
@@ -57,9 +55,27 @@ public class SiteResource {
     }
 
     @GET
-    @Path("/{siteIdOrUUID}")
+    @Path("/{siteId}")
     @Produces(MediaType.APPLICATION_JSON)
-    public RESTResponse<SiteEntity> getSiteByNameOrUUID(@PathParam("siteIdOrUUID")
String siteIdOrUUID){
-        return RESTResponse.async(()->siteEntityService.getBySiteIdOrUUID(siteIdOrUUID)).get();
+    public RESTResponse<SiteEntity> getSiteBySiteId(@PathParam("siteId") String siteId){
+        return RESTResponse.async(()->siteEntityService.getBySiteId(siteId)).get();
+    }
+
+    @DELETE
+    @Path("/{siteId}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public RESTResponse<SiteEntity> deleteSiteBySiteId(@PathParam("siteId") String
siteId){
+        return RESTResponse.async(()->siteEntityService.deleteBySiteId(siteId)).get();
+    }
+
+    @PUT
+    @Path("/{siteId}")
+    @Produces(MediaType.APPLICATION_JSON)
+    @Consumes(MediaType.APPLICATION_JSON)
+    public RESTResponse<SiteEntity> updateSite(@PathParam("siteId") String siteId,SiteEntity
siteEntity){
+        return RESTResponse.async(()-> {
+            siteEntity.setSiteId(siteId);
+            return siteEntityService.update(siteEntity);
+        }).get();
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0feba43d/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/service/SiteEntityService.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/service/SiteEntityService.java
b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/service/SiteEntityService.java
index 2f5254d..acea982 100644
--- a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/service/SiteEntityService.java
+++ b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/service/SiteEntityService.java
@@ -16,10 +16,12 @@
  */
 package org.apache.eagle.metadata.service;
 
+import org.apache.eagle.metadata.exceptions.EntityNotFoundException;
 import org.apache.eagle.metadata.model.SiteEntity;
 import org.apache.eagle.metadata.persistence.PersistenceService;
 
 public interface SiteEntityService extends PersistenceService<SiteEntity>{
-    SiteEntity getBySiteId(String siteId);
-    SiteEntity getBySiteIdOrUUID(String siteIdOrUUID);
+    SiteEntity getBySiteId(String siteId) throws EntityNotFoundException;
+    SiteEntity deleteBySiteId(String siteId) throws EntityNotFoundException;
+    SiteEntity update(SiteEntity siteEntity) throws EntityNotFoundException;
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0feba43d/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/service/memory/SiteEntityEntityServiceMemoryImpl.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/service/memory/SiteEntityEntityServiceMemoryImpl.java
b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/service/memory/SiteEntityEntityServiceMemoryImpl.java
index 8e27c53..f2a6f60 100644
--- a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/service/memory/SiteEntityEntityServiceMemoryImpl.java
+++ b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/service/memory/SiteEntityEntityServiceMemoryImpl.java
@@ -16,49 +16,71 @@
  */
 package org.apache.eagle.metadata.service.memory;
 
+import com.google.common.base.Preconditions;
 import com.google.inject.Singleton;
+import org.apache.eagle.metadata.exceptions.EntityNotFoundException;
 import org.apache.eagle.metadata.model.SiteEntity;
 import org.apache.eagle.metadata.service.SiteEntityService;
 
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Optional;
 
 @Singleton
 public class SiteEntityEntityServiceMemoryImpl implements SiteEntityService {
-    private Map<String,SiteEntity> nameSiteMap = new HashMap<>();
+    private Map<String,SiteEntity> siteId2EntityMap = new HashMap<>();
 
     @Override
     public Collection<SiteEntity> findAll() {
-        return nameSiteMap.values();
+        return siteId2EntityMap.values();
     }
 
     @Override
-    public SiteEntity getByUUID(String uuid) {
-        return nameSiteMap.values().stream().filter((site) -> uuid.equals(site.getUuid())).findAny().get();
+    public SiteEntity getByUUID(String uuid) throws EntityNotFoundException {
+        Optional<SiteEntity> entityOptional = siteId2EntityMap.values().stream().filter((site)
-> uuid.equals(site.getUuid())).findAny();
+        if(entityOptional.isPresent()){
+            return entityOptional.get();
+        }else{
+            throw new EntityNotFoundException("Site with UUID: "+uuid+" not found");
+        }
     }
 
     @Override
     public SiteEntity create(SiteEntity entity) {
-        if(getBySiteId(entity.getSiteId()) != null){
-            throw new IllegalArgumentException("Duplicated site: "+entity);
+        Preconditions.checkNotNull(entity.getSiteId(),"SiteId is null: "+entity.getSiteId());
+        if(siteId2EntityMap.containsKey(entity.getSiteId())){
+            throw new IllegalArgumentException("Duplicated siteId: "+entity.getSiteId());
         }
         entity.ensureDefault();
-        nameSiteMap.put(entity.getSiteId(),entity);
+        siteId2EntityMap.put(entity.getSiteId(),entity);
         return entity;
     }
 
     @Override
-    public SiteEntity getBySiteId(String siteName) {
-        return nameSiteMap.get(siteName);
+    public SiteEntity getBySiteId(String siteId) throws EntityNotFoundException {
+        if(!siteId2EntityMap.containsKey(siteId)){
+            throw new EntityNotFoundException("Site with siteId: "+siteId+" not exists");
+        }
+        return siteId2EntityMap.get(siteId);
+    }
+
+
+    @Override
+    public SiteEntity deleteBySiteId(String siteId) throws EntityNotFoundException {
+        return siteId2EntityMap.remove(getBySiteId(siteId).getSiteId());
     }
 
     @Override
-    public SiteEntity getBySiteIdOrUUID(String siteNameOrUUID) {
-        if(nameSiteMap.containsKey(siteNameOrUUID)){
-            return nameSiteMap.get(siteNameOrUUID);
-        } else {
-            return getByUUID(siteNameOrUUID);
+    public SiteEntity update(SiteEntity siteEntity) throws EntityNotFoundException {
+        if(siteEntity.getSiteId() == null && siteEntity.getUuid() == null){
+            throw new IllegalArgumentException("siteId and UUID are both null, don't know
how to update");
         }
+        SiteEntity oldEntity = (siteEntity.getSiteId()!=null)? getBySiteId(siteEntity.getSiteId())
: getByUUID(siteEntity.getUuid());
+        siteEntity.setUuid(oldEntity.getUuid());
+        siteEntity.setCreatedTime(oldEntity.getCreatedTime());
+        siteEntity.ensureDefault();
+        siteId2EntityMap.put(siteEntity.getSiteId(),siteEntity);
+        return siteEntity;
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/0feba43d/eagle-server/src/main/java/org/apache/eagle/server/RESTExceptionMapper.java
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/java/org/apache/eagle/server/RESTExceptionMapper.java b/eagle-server/src/main/java/org/apache/eagle/server/RESTExceptionMapper.java
index 2d257a4..ba7963f 100644
--- a/eagle-server/src/main/java/org/apache/eagle/server/RESTExceptionMapper.java
+++ b/eagle-server/src/main/java/org/apache/eagle/server/RESTExceptionMapper.java
@@ -18,6 +18,7 @@ package org.apache.eagle.server;
 
 import io.dropwizard.jersey.errors.LoggingExceptionMapper;
 import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.apache.eagle.metadata.resource.RESTResponse;
 
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
@@ -32,31 +33,6 @@ public class RESTExceptionMapper extends LoggingExceptionMapper<Throwable>
{
         }
         final long id = ThreadLocalRandom.current().nextLong();
         logException(id, throwable);
-       return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new ExceptionResponseEntity(throwable)).type(MediaType.APPLICATION_JSON_TYPE).build();
-    }
-
-    public static class ExceptionResponseEntity {
-        public ExceptionResponseEntity(Throwable throwable){
-            this.setMessage(ExceptionUtils.getMessage(throwable));
-            this.setException(ExceptionUtils.getStackTrace(throwable));
-        }
-        private String message;
-        private String exception;
-
-        public String getException() {
-            return exception;
-        }
-
-        public void setException(String exception) {
-            this.exception = exception;
-        }
-
-        public String getMessage() {
-            return message;
-        }
-
-        public void setMessage(String message) {
-            this.message = message;
-        }
+       return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new RESTResponse<>(throwable)).type(MediaType.APPLICATION_JSON_TYPE).build();
     }
 }
\ No newline at end of file


Mime
View raw message