From 68e65da38499fdb171ee669b6060266ecaad89e9 Mon Sep 17 00:00:00 2001 From: "shashikanth.vh@huawei.com" Date: Fri, 28 Aug 2020 07:34:49 +0530 Subject: [PATCH 1/6] app instance info --- pom.xml | 130 +++++++---- .../apihandler/AppInstanceInfoHandler.java | 211 ++++++++++++++++++ .../apihandler/AppOrchestratorHandler.java | 98 ++++---- .../mecm/appo/apihandler/CreateParam.java | 12 +- .../mecm/appo/exception/AppoDbException.java | 8 + .../appo/service/AppInstanceInfoService.java | 53 +++++ .../AppoProcessflowService.java | 18 +- .../service/{interfaces => }/AppoService.java | 20 +- 8 files changed, 443 insertions(+), 107 deletions(-) create mode 100644 src/main/java/org/edgegallery/mecm/appo/apihandler/AppInstanceInfoHandler.java create mode 100644 src/main/java/org/edgegallery/mecm/appo/exception/AppoDbException.java create mode 100644 src/main/java/org/edgegallery/mecm/appo/service/AppInstanceInfoService.java rename src/main/java/org/edgegallery/mecm/appo/service/{interfaces => }/AppoProcessflowService.java (53%) rename src/main/java/org/edgegallery/mecm/appo/service/{interfaces => }/AppoService.java (80%) diff --git a/pom.xml b/pom.xml index e3c606f..c455b7a 100755 --- a/pom.xml +++ b/pom.xml @@ -14,21 +14,22 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> - - 4.0.0 - + + 4.0.0 org.edgegallery.mecm appo 0.0.1-SNAPSHOT - appo Application Orchestrator - + + 3.4.0 + 7.10.0 1.8 + 1.18.10 UTF-8 2.2.6.RELEASE - 1.18.10 2.2.2.RELEASE @@ -39,39 +40,45 @@ spring-boot-dependencies ${spring-boot.version} pom - import + import + - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-logging - - + camunda-bpm-spring-boot-starter-webapp + org.camunda.bpm.springboot + ${camunda.springboot.version} + + + com.h2database + h2 + test - org.springframework.boot spring-boot-starter-test + org.springframework.boot test - + + spring-boot-starter-jdbc + org.springframework.boot + + + + org.apache.logging.log4j log4j-core 2.13.2 - + org.apache.logging.log4j log4j-api 2.13.2 - + org.apache.logging.log4j log4j-slf4j-impl 2.13.2 @@ -81,6 +88,37 @@ log4j-jcl 2.13.2 + + + + + jackson-mapper-asl + org.codehaus.jackson + + + org.springframework.security.oauth.boot + spring-security-oauth2-autoconfigure + ${spring-security-oauth2-autoconfigure.version} + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-validation + + + org.apache.commons + commons-collections4 + 4.4 + + + + com.google.code.gson + gson + 2.8.2 + io.springfox @@ -93,32 +131,39 @@ 2.9.2 + + + + + - org.projectlombok - lombok - ${lombok.version} + org.springframework.boot + spring-boot-starter-data-jpa + - gson - com.google.code.gson - 2.8.2 + org.modelmapper + modelmapper + 1.1.0 - spring-security-oauth2-autoconfigure - - - jackson-mapper-asl - org.codehaus.jackson - - - org.springframework.security.oauth.boot - ${spring-security-oauth2-autoconfigure.version} - + org.springframework.boot + spring-boot-starter-tomcat + + + org.projectlombok + lombok + ${lombok.version} + + + + + - + - + -Xlint:all true @@ -130,7 +175,7 @@ maven-compiler-plugin 3.1 - + @@ -142,7 +187,7 @@ spring-boot-maven-plugin 2.1.2.RELEASE - + https://raw.githubusercontent.com/EdgeGallery/infra/master/configs/edgegallery_checks.xml @@ -162,7 +207,7 @@ maven-checkstyle-plugin 3.1.1 - + true 2 @@ -180,7 +225,7 @@ maven-pmd-plugin 3.13.0 - + true @@ -197,5 +242,6 @@ + diff --git a/src/main/java/org/edgegallery/mecm/appo/apihandler/AppInstanceInfoHandler.java b/src/main/java/org/edgegallery/mecm/appo/apihandler/AppInstanceInfoHandler.java new file mode 100644 index 0000000..2f8a550 --- /dev/null +++ b/src/main/java/org/edgegallery/mecm/appo/apihandler/AppInstanceInfoHandler.java @@ -0,0 +1,211 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd. + * + * Licensed 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.edgegallery.mecm.appo.apihandler; + +import static org.edgegallery.mecm.appo.common.Constants.APP_INST_ID_REGX; +import static org.edgegallery.mecm.appo.common.Constants.TENENT_ID_REGEX; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import java.util.LinkedList; +import java.util.List; +import javax.validation.Valid; +import javax.validation.constraints.Pattern; +import org.edgegallery.mecm.appo.apihandler.dto.AppInstanceInfoDto; +import org.edgegallery.mecm.appo.exception.AppoDbException; +import org.edgegallery.mecm.appo.model.AppInstanceInfo; +import org.edgegallery.mecm.appo.service.AppInstanceInfoService; +import org.modelmapper.ModelMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Application instance info API handler. + */ +@Api(value = "Application instance info api system") +@Validated +@RequestMapping("/appo/v1") +@RestController +public class AppInstanceInfoHandler { + + private static final Logger logger = LoggerFactory.getLogger(AppInstanceInfoHandler.class); + + private AppInstanceInfoService appInstanceInfoService; + + @Autowired + public AppInstanceInfoHandler(AppInstanceInfoService appInstanceInfoService) { + this.appInstanceInfoService = appInstanceInfoService; + } + + /** + * Retrieves application instance information. + * + * @param accessToken access token + * @param tenantId tenant ID + * @param appInstanceId application instance ID + * @return application instance information + */ + @ApiOperation(value = "Retrieves application instance info", response = AppInstanceInfoDto.class) + @GetMapping(path = "/tenants/{tenant_id}/app_instance_infos/{appInstance_id}", + produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity getAppInstanceInfo( + @ApiParam(value = "access token") + @RequestHeader("access_token") String accessToken, + @ApiParam(value = "tenant id") @PathVariable("tenant_id") + @Pattern(regexp = TENENT_ID_REGEX) String tenantId, + @ApiParam(value = "application instance id") @PathVariable("appInstance_id") + @Pattern(regexp = APP_INST_ID_REGX) String appInstanceId) { + + AppInstanceInfo appInstanceInfo = null; + AppInstanceInfoDto dto = null; + try { + appInstanceInfo = appInstanceInfoService.getAppInstanceInfo(tenantId, appInstanceId); + ModelMapper mapper = new ModelMapper(); + dto = mapper.map(appInstanceInfo, AppInstanceInfoDto.class); + } catch (AppoDbException e) { + logger.debug("Query app instance info failed: {}", e.getMessage()); + } + return new ResponseEntity<>(dto, HttpStatus.OK); + } + + /** + * Retrieves application instance information. + * + * @param accessToken access token + * @param tenantId tenant ID + * @return application instance information + */ + @ApiOperation(value = "Retrieves application instance info", response = List.class) + @GetMapping(value = "/tenants/{tenant_id}/app_instance_infos", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity> getAllAppInstanceInfo( + @ApiParam(value = "access token") @RequestHeader("access_token") String accessToken, + @ApiParam(value = "tenant id") @PathVariable("tenant_id") + @Pattern(regexp = TENENT_ID_REGEX) String tenantId) { + List appInstanceInfos = null; + List appInstanceInfosDto = new LinkedList<>(); + try { + appInstanceInfos = appInstanceInfoService.getAllAppInstanceInfo(tenantId); + for (AppInstanceInfo tenantAppInstanceInfo : appInstanceInfos) { + ModelMapper mapper = new ModelMapper(); + appInstanceInfosDto.add(mapper.map(tenantAppInstanceInfo, AppInstanceInfoDto.class)); + } + } catch (AppoDbException e) { + logger.debug("Query all app instance info failed: {}", e.getMessage()); + } + return new ResponseEntity<>(appInstanceInfosDto, HttpStatus.OK); + } + + /** + * Creates application instance information. + * + * @param accessToken access token + * @param tenantId tenant ID + * @param appInstInfoDto application instance info + * @return application instance information + */ + @ApiOperation(value = "Creates application instance info", response = AppInstanceInfoDto.class) + @PostMapping(path = "/tenants/{tenant_id}/app_instance_infos", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity createAppInstanceInfo( + @ApiParam(value = "access token") @RequestHeader("access_token") String accessToken, + @ApiParam(value = "tenant id") @PathVariable("tenant_id") + @Pattern(regexp = TENENT_ID_REGEX) String tenantId, + @ApiParam(value = "application instance") @RequestBody AppInstanceInfoDto appInstInfoDto) { + ModelMapper mapper = new ModelMapper(); + AppInstanceInfo appInstanceInfo = mapper.map(appInstInfoDto, AppInstanceInfo.class); + AppInstanceInfoDto dto = null; + try { + appInstanceInfo = appInstanceInfoService.createAppInstanceInfo(tenantId, appInstanceInfo); + dto = mapper.map(appInstanceInfo, AppInstanceInfoDto.class); + } catch (AppoDbException e) { + logger.debug("Create app instance info failed: {}", e.getMessage()); + } + return new ResponseEntity<>(dto, HttpStatus.OK); + } + + /** + * Deletes application instance information. + * + * @param accessToken access token + * @param tenantId tenant ID + * @param appInstanceId application instance ID + */ + @ApiOperation(value = "Deletes application instance info", response = String.class) + @DeleteMapping(path = "/tenants/{tenant_id}/app_instance_infos/{appInstance_id}", + produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity deleteAppInstanceInfo( + @ApiParam(value = "access token") @RequestHeader("access_token") String accessToken, + @ApiParam(value = "tenant id") @PathVariable("tenant_id") + @Pattern(regexp = TENENT_ID_REGEX) String tenantId, + @ApiParam(value = "application instance id") @PathVariable("appInstance_id") + @Pattern(regexp = APP_INST_ID_REGX) String appInstanceId) { + + try { + appInstanceInfoService.deleteAppInstanceInfo(tenantId, appInstanceId); + } catch (AppoDbException e) { + logger.debug("Delete app instance info failed: {}", e.getMessage()); + } + + return new ResponseEntity<>("success", HttpStatus.OK); + } + + /** + * Updates application instance information. + * + * @param accessToken access token + * @param tenantId tenant ID + * @param instInfo application instance info + * @return application instance information + */ + @ApiOperation(value = "Creates application instance info", response = AppInstanceInfoDto.class) + @PutMapping(path = "/tenants/{tenant_id}/app_instance_infos/{appInstance_id}", + produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity updateAppInstanceInfo( + @ApiParam(value = "access token") @RequestHeader("access_token") String accessToken, + @ApiParam(value = "tenant id") @PathVariable("tenant_id") + @Pattern(regexp = TENENT_ID_REGEX) String tenantId, + @ApiParam(value = "application instance id") @PathVariable("appInstance_id") + @Pattern(regexp = APP_INST_ID_REGX) String appInstanceId, + @ApiParam(value = "application instance") @Valid @RequestBody AppInstanceInfoDto instInfo) { + + ModelMapper mapper = new ModelMapper(); + AppInstanceInfo appInstanceInfo = mapper.map(instInfo, AppInstanceInfo.class); + appInstanceInfo.setAppInstanceId(appInstanceId); + AppInstanceInfoDto dto = null; + try { + appInstanceInfo = appInstanceInfoService.updateAppInstanceInfo(tenantId, appInstanceInfo); + dto = mapper.map(appInstanceInfo, AppInstanceInfoDto.class); + } catch (AppoDbException e) { + logger.debug("Update app instance info failed: {}", e.getMessage()); + } + return new ResponseEntity<>(dto, HttpStatus.OK); + } +} \ No newline at end of file diff --git a/src/main/java/org/edgegallery/mecm/appo/apihandler/AppOrchestratorHandler.java b/src/main/java/org/edgegallery/mecm/appo/apihandler/AppOrchestratorHandler.java index 3c3a47e..856a618 100644 --- a/src/main/java/org/edgegallery/mecm/appo/apihandler/AppOrchestratorHandler.java +++ b/src/main/java/org/edgegallery/mecm/appo/apihandler/AppOrchestratorHandler.java @@ -20,6 +20,7 @@ import static org.edgegallery.mecm.appo.common.Constants.TENENT_ID_REGEX; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; import java.util.List; @@ -27,18 +28,20 @@ import java.util.Map; import javax.validation.Valid; import javax.validation.constraints.Pattern; import org.edgegallery.mecm.appo.model.AppInstanceInfo; -import org.edgegallery.mecm.appo.service.interfaces.AppoService; +import org.edgegallery.mecm.appo.service.AppoService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; /** @@ -63,16 +66,16 @@ public class AppOrchestratorHandler { * @return application instance ID on success, error code on failure */ @ApiOperation(value = "Creates application instance", response = Map.class) - @RequestMapping(path = "/tenants/{tenant_id}/app_instances", - method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) + @PostMapping(path = "/tenants/{tenant_id}/app_instances", produces = MediaType.APPLICATION_JSON_VALUE) @ApiResponses(value = { @ApiResponse(code = 201, message = "request accepted ", response = String.class), @ApiResponse(code = 500, message = "internal server error", response = String.class) }) - public ResponseEntity> createAppInstance(@RequestHeader("access_token") String accessToken, - @PathVariable("tenant_id") - @Pattern(regexp = TENENT_ID_REGEX) String tenantId, - @Valid @RequestBody CreateParam createParam) { + public ResponseEntity> createAppInstance( + @ApiParam(value = "access token") @RequestHeader("access_token") String accessToken, + @ApiParam(value = "tenant id") @PathVariable("tenant_id") + @Pattern(regexp = TENENT_ID_REGEX) String tenantId, + @ApiParam(value = "create application instance") @Valid @RequestBody CreateParam createParam) { logger.debug("Application create request received..."); return appoService.createAppInstance(accessToken, tenantId, createParam); @@ -86,16 +89,16 @@ public class AppOrchestratorHandler { * @return status code 201, error code on failure */ @ApiOperation(value = "Instantiate application instance", response = String.class) - @RequestMapping(path = "/tenants/{tenant_id}/app_instances/{app_instance_id}", - method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE) + @PostMapping(path = "/tenants/{tenant_id}/app_instances/{app_instance_id}", produces = MediaType.TEXT_PLAIN_VALUE) @ApiResponses(value = { @ApiResponse(code = 201, message = "request accepted ", response = String.class), @ApiResponse(code = 500, message = "internal server error", response = String.class) }) - public ResponseEntity instantiateAppInstance(@RequestHeader("access_token") String accessToken, - @PathVariable("tenant_id") - @Pattern(regexp = TENENT_ID_REGEX) String tenantId, - @PathVariable("app_instance_id") String appInstanceId) { + public ResponseEntity instantiateAppInstance( + @ApiParam(value = "access token") @RequestHeader("access_token") String accessToken, + @ApiParam(value = "tenant id") @PathVariable("tenant_id") + @Pattern(regexp = TENENT_ID_REGEX) String tenantId, + @ApiParam(value = "application instance id") @PathVariable("app_instance_id") String appInstanceId) { logger.debug("Application instantiation request received..."); return appoService.instantiateAppInstance(accessToken, tenantId, appInstanceId); @@ -108,13 +111,14 @@ public class AppOrchestratorHandler { * @param appInstanceId application instance ID * @return application instance info & status code 200 on success, error code on failure */ - @ApiOperation(value = "Retrieves application instance information", response = AppInstanceInfo.class) - @RequestMapping(path = "/tenants/{tenant_id}/app_instances/{app_instance_id}", - method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity getAppInstance(@RequestHeader("access_token") String accessToken, - @PathVariable("tenant_id") - @Pattern(regexp = TENENT_ID_REGEX) String tenantId, - @PathVariable("app_instance_id") String appInstanceId) { + @ApiOperation(value = "Retrieves application instance information", response = String.class) + @GetMapping(path = "/tenants/{tenant_id}/app_instances/{app_instance_id}", + produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity getAppInstance( + @ApiParam(value = "access token") @RequestHeader("access_token") String accessToken, + @ApiParam(value = "tenant id") @PathVariable("tenant_id") + @Pattern(regexp = TENENT_ID_REGEX) String tenantId, + @ApiParam(value = "application instance id") @PathVariable("app_instance_id") String appInstanceId) { logger.debug("Query application info request received..."); return appoService.getAppInstance(accessToken, tenantId, appInstanceId); @@ -127,11 +131,11 @@ public class AppOrchestratorHandler { * @return all application instances & status code 200 on success, error code on failure */ @ApiOperation(value = "Retrieves application instance information", response = List.class) - @RequestMapping(path = "/tenants/{tenant_id}/app_instances", - method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> getAllAppInstance(@RequestHeader("access_token") String accessToken, - @PathVariable("tenant_id") - @Pattern(regexp = TENENT_ID_REGEX) String tenantId) { + @GetMapping(path = "/tenants/{tenant_id}/app_instances", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity> getAllAppInstance( + @ApiParam(value = "access token") @RequestHeader("access_token") String accessToken, + @ApiParam(value = "tenant id") @PathVariable("tenant_id") + @Pattern(regexp = TENENT_ID_REGEX) String tenantId) { logger.debug("Query all application info request received..."); return appoService.getAllAppInstance(accessToken, tenantId); @@ -145,16 +149,17 @@ public class AppOrchestratorHandler { * @return status code 201, error code on failure */ @ApiOperation(value = "Terminates application instance", response = String.class) - @RequestMapping(path = "/tenant/{tenant_id}/app_instances/{app_instance_id}", - method = RequestMethod.DELETE, produces = MediaType.TEXT_PLAIN_VALUE) + @DeleteMapping(path = "/tenants/{tenant_id}/app_instances/{app_instance_id}", + produces = MediaType.APPLICATION_JSON_VALUE) @ApiResponses(value = { @ApiResponse(code = 201, message = "request accepted ", response = String.class), @ApiResponse(code = 500, message = "internal server error", response = String.class) }) - public ResponseEntity terminateAppInstance(@RequestHeader("access_token") String accessToken, - @PathVariable("tenant_id") - @Pattern(regexp = TENENT_ID_REGEX) String tenantId, - @PathVariable("app_instance_id") String appInstanceId) { + public ResponseEntity terminateAppInstance( + @ApiParam(value = "access token") @RequestHeader("access_token") String accessToken, + @ApiParam(value = "tenant id") @PathVariable("tenant_id") + @Pattern(regexp = TENENT_ID_REGEX) String tenantId, + @ApiParam(value = "application instance id") @PathVariable("app_instance_id") String appInstanceId) { logger.debug("Terminate application info request received..."); return appoService.terminateAppInstance(accessToken, tenantId, appInstanceId); @@ -168,12 +173,11 @@ public class AppOrchestratorHandler { * @return status code 200 on success, error code on failure */ @ApiOperation(value = "Retrieves edge host performance statistics", response = String.class) - @RequestMapping(path = "/tenant/{tenant_id}/hosts/{host_ip}/kpi", - method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity queryKpi(@RequestHeader("access_token") String accessToken, - @PathVariable("tenant_id") - @Pattern(regexp = TENENT_ID_REGEX) String tenantId, - @PathVariable("host_ip") String hostIp) { + @GetMapping(path = "/tenants/{tenant_id}/hosts/{host_ip}/kpi", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity queryKpi( + @ApiParam(value = "access token") @RequestHeader("access_token") String accessToken, + @PathVariable("tenant_id") @Pattern(regexp = TENENT_ID_REGEX) String tenantId, + @ApiParam(value = "edge host ip") @PathVariable("host_ip") String hostIp) { logger.debug("Query KPI request received..."); return appoService.queryKpi(accessToken, tenantId, hostIp); @@ -187,19 +191,15 @@ public class AppOrchestratorHandler { * @return status code 200 on success, error code on failure */ @ApiOperation(value = "Retrieves edge host platform capabilities", response = String.class) - @RequestMapping(path = "/tenant/{tenant_id}/hosts/{host_ip}/mep_capabilities", - method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity queryEdgehostCapabilities(@RequestHeader("access_token") String accessToken, - @PathVariable("tenant_id") - @Pattern(regexp = TENENT_ID_REGEX) String tenantId, - @PathVariable("host_ip") String hostIp) { + @GetMapping(path = "/tenants/{tenant_id}/hosts/{host_ip}/mep_capabilities", + produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity queryEdgehostCapabilities( + @ApiParam(value = "access token") @RequestHeader("access_token") String accessToken, + @ApiParam(value = "tenant id") @PathVariable("tenant_id") + @Pattern(regexp = TENENT_ID_REGEX) String tenantId, + @ApiParam(value = "edge host ip") @PathVariable("host_ip") String hostIp) { logger.debug("Query MEP capabilities request received..."); return appoService.queryEdgehostCapabilities(accessToken, tenantId, hostIp); } - - /* - TODO: TBD - 1. Application container usage info from host - */ } diff --git a/src/main/java/org/edgegallery/mecm/appo/apihandler/CreateParam.java b/src/main/java/org/edgegallery/mecm/appo/apihandler/CreateParam.java index c0b593d..f8ce060 100755 --- a/src/main/java/org/edgegallery/mecm/appo/apihandler/CreateParam.java +++ b/src/main/java/org/edgegallery/mecm/appo/apihandler/CreateParam.java @@ -26,6 +26,7 @@ import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; import org.springframework.validation.annotation.Validated; @@ -37,30 +38,31 @@ import org.springframework.validation.annotation.Validated; @Getter @Setter @ToString +@NoArgsConstructor @AllArgsConstructor public final class CreateParam { @NotEmpty(message = "Package ID is mandatory") - @Size(max = 50) + @Size(max = 64) @Pattern(regexp = APP_PKG_ID_REGX) private String appPackageId; @NotEmpty(message = "Application name is mandatory") - @Size(max = 200) + @Size(max = 128) @Pattern(regexp = APP_NAME_REGEX) private String appName; @NotEmpty(message = "Application instance descriptor ID is mandatory") - @Size(max = 50) + @Size(max = 64) @Pattern(regexp = APPD_ID_REGEX) private String appdId; @NotEmpty(message = "Application instance descriptor is mandatory") - @Size(max = 300) + @Size(max = 256) private String appInstanceDescription; @NotEmpty(message = "MEC host is mandatory") - @Size(max = 40) + @Size(max = 15) @Pattern(regexp = HOST_IP_REGX) private String mecHost; } diff --git a/src/main/java/org/edgegallery/mecm/appo/exception/AppoDbException.java b/src/main/java/org/edgegallery/mecm/appo/exception/AppoDbException.java new file mode 100644 index 0000000..d85b5bc --- /dev/null +++ b/src/main/java/org/edgegallery/mecm/appo/exception/AppoDbException.java @@ -0,0 +1,8 @@ +package org.edgegallery.mecm.appo.exception; + +public class AppoDbException extends Exception { + + public AppoDbException(String msg) { + super(msg); + } +} diff --git a/src/main/java/org/edgegallery/mecm/appo/service/AppInstanceInfoService.java b/src/main/java/org/edgegallery/mecm/appo/service/AppInstanceInfoService.java new file mode 100644 index 0000000..537b3af --- /dev/null +++ b/src/main/java/org/edgegallery/mecm/appo/service/AppInstanceInfoService.java @@ -0,0 +1,53 @@ +package org.edgegallery.mecm.appo.service; + +import java.util.List; +import org.edgegallery.mecm.appo.exception.AppoDbException; +import org.edgegallery.mecm.appo.model.AppInstanceInfo; + +public interface AppInstanceInfoService { + + /** + * Retrieves application instance information. + * + * @param tenantId tenant ID + * @param appInstanceId application instance ID + * @return application instance information + */ + AppInstanceInfo getAppInstanceInfo(String tenantId, String appInstanceId) throws AppoDbException; + + /** + * Retrieves all application instance information. + * + * @param tenantId tenant ID + * @return application instance information + */ + List getAllAppInstanceInfo(String tenantId) throws AppoDbException; + + /** + * Creates application instance info. + * + * @param tenantId tenant ID + * @param appInstanceInfo application information + * @return application information + */ + AppInstanceInfo createAppInstanceInfo(String tenantId, + AppInstanceInfo appInstanceInfo) throws AppoDbException; + + /** + * Deletes application instance information. + * + * @param tenantId tenant ID + * @param appInstanceId application instance ID + */ + void deleteAppInstanceInfo(String tenantId, String appInstanceId) throws AppoDbException; + + /** + * Updates application instance info. + * + * @param tenantId tenant ID + * @param appInstanceInfo application information + * @return application information + */ + AppInstanceInfo updateAppInstanceInfo(String tenantId, + AppInstanceInfo appInstanceInfo) throws AppoDbException; +} diff --git a/src/main/java/org/edgegallery/mecm/appo/service/interfaces/AppoProcessflowService.java b/src/main/java/org/edgegallery/mecm/appo/service/AppoProcessflowService.java similarity index 53% rename from src/main/java/org/edgegallery/mecm/appo/service/interfaces/AppoProcessflowService.java rename to src/main/java/org/edgegallery/mecm/appo/service/AppoProcessflowService.java index da1a400..622fe3f 100644 --- a/src/main/java/org/edgegallery/mecm/appo/service/interfaces/AppoProcessflowService.java +++ b/src/main/java/org/edgegallery/mecm/appo/service/AppoProcessflowService.java @@ -1,4 +1,20 @@ -package org.edgegallery.mecm.appo.service.interfaces; +/* + * Copyright 2020 Huawei Technologies Co., Ltd. + * + * Licensed 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.edgegallery.mecm.appo.service; import java.util.Map; import org.edgegallery.mecm.appo.common.AppoProcessFlowResponse; diff --git a/src/main/java/org/edgegallery/mecm/appo/service/interfaces/AppoService.java b/src/main/java/org/edgegallery/mecm/appo/service/AppoService.java similarity index 80% rename from src/main/java/org/edgegallery/mecm/appo/service/interfaces/AppoService.java rename to src/main/java/org/edgegallery/mecm/appo/service/AppoService.java index a5f6158..a8352d9 100644 --- a/src/main/java/org/edgegallery/mecm/appo/service/interfaces/AppoService.java +++ b/src/main/java/org/edgegallery/mecm/appo/service/AppoService.java @@ -1,4 +1,4 @@ -package org.edgegallery.mecm.appo.service.interfaces; +package org.edgegallery.mecm.appo.service; import java.util.List; import java.util.Map; @@ -18,7 +18,7 @@ public interface AppoService { * @return application instance ID on success, error code on failure */ - public ResponseEntity> createAppInstance(String accessToken, + ResponseEntity> createAppInstance(String accessToken, String tenantId, CreateParam createParam); @@ -31,7 +31,7 @@ public interface AppoService { * @return status code 200 on success, error code on failure */ - public ResponseEntity instantiateAppInstance(String accessToken, + ResponseEntity instantiateAppInstance(String accessToken, String tenantId, String appInstanceId); @@ -44,9 +44,9 @@ public interface AppoService { * @return application instance info & status code 200 on success, error code on failure */ - public ResponseEntity getAppInstance(String accessToken, - String tenantId, - String appInstanceId); + ResponseEntity getAppInstance(String accessToken, + String tenantId, + String appInstanceId); /** * Retrieves all application instance information. @@ -56,7 +56,7 @@ public interface AppoService { * @return all application instances & status code 200 on success, error code on failure */ - public ResponseEntity> getAllAppInstance(String accessToken, + ResponseEntity> getAllAppInstance(String accessToken, String tenantId); /** @@ -68,7 +68,7 @@ public interface AppoService { * @return status code 200 on success, error code on failure */ - public ResponseEntity terminateAppInstance(String accessToken, + ResponseEntity terminateAppInstance(String accessToken, String tenantId, String appInstanceId); @@ -81,7 +81,7 @@ public interface AppoService { * @return status code 200 on success, error code on failure */ - public ResponseEntity queryKpi(String accessToken, + ResponseEntity queryKpi(String accessToken, String tenantId, String hostIp); @@ -94,7 +94,7 @@ public interface AppoService { * @return status code 200 on success, error code on failure */ - public ResponseEntity queryEdgehostCapabilities(String accessToken, + ResponseEntity queryEdgehostCapabilities(String accessToken, String tenantId, String hostIp); } -- Gitee From 01d01f4b9916306eee3903b1b31b482cf91b270a Mon Sep 17 00:00:00 2001 From: "shashikanth.vh@huawei.com" Date: Fri, 28 Aug 2020 07:39:47 +0530 Subject: [PATCH 2/6] app instance info repository --- .../mecm/appo/repository/AppInstanceInfoRepository.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/main/java/org/edgegallery/mecm/appo/repository/AppInstanceInfoRepository.java diff --git a/src/main/java/org/edgegallery/mecm/appo/repository/AppInstanceInfoRepository.java b/src/main/java/org/edgegallery/mecm/appo/repository/AppInstanceInfoRepository.java new file mode 100644 index 0000000..8c9ffe8 --- /dev/null +++ b/src/main/java/org/edgegallery/mecm/appo/repository/AppInstanceInfoRepository.java @@ -0,0 +1,8 @@ +package org.edgegallery.mecm.appo.repository; + +import org.edgegallery.mecm.appo.model.AppInstanceInfo; +import org.springframework.data.repository.CrudRepository; + +public interface AppInstanceInfoRepository extends CrudRepository { + +} -- Gitee From 31e4952360ef60417269001a1effe5e3409d63e9 Mon Sep 17 00:00:00 2001 From: "shashikanth.vh@huawei.com" Date: Fri, 28 Aug 2020 07:43:51 +0530 Subject: [PATCH 3/6] header update --- .../repository/AppInstanceInfoRepository.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/org/edgegallery/mecm/appo/repository/AppInstanceInfoRepository.java b/src/main/java/org/edgegallery/mecm/appo/repository/AppInstanceInfoRepository.java index 8c9ffe8..26e6de2 100644 --- a/src/main/java/org/edgegallery/mecm/appo/repository/AppInstanceInfoRepository.java +++ b/src/main/java/org/edgegallery/mecm/appo/repository/AppInstanceInfoRepository.java @@ -1,3 +1,19 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd. + * + * Licensed 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.edgegallery.mecm.appo.repository; import org.edgegallery.mecm.appo.model.AppInstanceInfo; -- Gitee From 22fb216665b8c60d0cf753d660604acc110c1aa7 Mon Sep 17 00:00:00 2001 From: "shashikanth.vh@huawei.com" Date: Fri, 28 Aug 2020 07:57:36 +0530 Subject: [PATCH 4/6] static tool indentation issue fix --- .../apihandler/AppOrchestratorHandler.java | 70 ++++++++++--------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/src/main/java/org/edgegallery/mecm/appo/apihandler/AppOrchestratorHandler.java b/src/main/java/org/edgegallery/mecm/appo/apihandler/AppOrchestratorHandler.java index 856a618..51af1a9 100644 --- a/src/main/java/org/edgegallery/mecm/appo/apihandler/AppOrchestratorHandler.java +++ b/src/main/java/org/edgegallery/mecm/appo/apihandler/AppOrchestratorHandler.java @@ -67,15 +67,15 @@ public class AppOrchestratorHandler { */ @ApiOperation(value = "Creates application instance", response = Map.class) @PostMapping(path = "/tenants/{tenant_id}/app_instances", produces = MediaType.APPLICATION_JSON_VALUE) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "request accepted ", response = String.class), - @ApiResponse(code = 500, message = "internal server error", response = String.class) - }) + @ApiResponses(value = {@ApiResponse(code = 201, message = "request accepted ", response = String.class), + @ApiResponse(code = 500, message = "internal server error", response = String.class) + }) public ResponseEntity> createAppInstance( - @ApiParam(value = "access token") @RequestHeader("access_token") String accessToken, - @ApiParam(value = "tenant id") @PathVariable("tenant_id") - @Pattern(regexp = TENENT_ID_REGEX) String tenantId, - @ApiParam(value = "create application instance") @Valid @RequestBody CreateParam createParam) { + @ApiParam(value = "access token") @RequestHeader("access_token") String accessToken, + @ApiParam(value = "tenant id") @PathVariable("tenant_id") + @Pattern(regexp = TENENT_ID_REGEX) String tenantId, + @ApiParam(value = "create application instance") + @Valid @RequestBody CreateParam createParam) { logger.debug("Application create request received..."); return appoService.createAppInstance(accessToken, tenantId, createParam); @@ -90,10 +90,9 @@ public class AppOrchestratorHandler { */ @ApiOperation(value = "Instantiate application instance", response = String.class) @PostMapping(path = "/tenants/{tenant_id}/app_instances/{app_instance_id}", produces = MediaType.TEXT_PLAIN_VALUE) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "request accepted ", response = String.class), - @ApiResponse(code = 500, message = "internal server error", response = String.class) - }) + @ApiResponses(value = {@ApiResponse(code = 201, message = "request accepted ", response = String.class), + @ApiResponse(code = 500, message = "internal server error", response = String.class) + }) public ResponseEntity instantiateAppInstance( @ApiParam(value = "access token") @RequestHeader("access_token") String accessToken, @ApiParam(value = "tenant id") @PathVariable("tenant_id") @@ -114,11 +113,12 @@ public class AppOrchestratorHandler { @ApiOperation(value = "Retrieves application instance information", response = String.class) @GetMapping(path = "/tenants/{tenant_id}/app_instances/{app_instance_id}", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity getAppInstance( - @ApiParam(value = "access token") @RequestHeader("access_token") String accessToken, - @ApiParam(value = "tenant id") @PathVariable("tenant_id") - @Pattern(regexp = TENENT_ID_REGEX) String tenantId, - @ApiParam(value = "application instance id") @PathVariable("app_instance_id") String appInstanceId) { + public ResponseEntity getAppInstance(@ApiParam(value = "access token") + @RequestHeader("access_token") String accessToken, + @ApiParam(value = "tenant id") @PathVariable("tenant_id") + @Pattern(regexp = TENENT_ID_REGEX) String tenantId, + @ApiParam(value = "application instance id") + @PathVariable("app_instance_id") String appInstanceId) { logger.debug("Query application info request received..."); return appoService.getAppInstance(accessToken, tenantId, appInstanceId); @@ -132,10 +132,11 @@ public class AppOrchestratorHandler { */ @ApiOperation(value = "Retrieves application instance information", response = List.class) @GetMapping(path = "/tenants/{tenant_id}/app_instances", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> getAllAppInstance( - @ApiParam(value = "access token") @RequestHeader("access_token") String accessToken, - @ApiParam(value = "tenant id") @PathVariable("tenant_id") - @Pattern(regexp = TENENT_ID_REGEX) String tenantId) { + public ResponseEntity> getAllAppInstance(@ApiParam(value = "access token") + @RequestHeader("access_token") String accessToken, + @ApiParam(value = "tenant id") + @PathVariable("tenant_id") + @Pattern(regexp = TENENT_ID_REGEX) String tenantId) { logger.debug("Query all application info request received..."); return appoService.getAllAppInstance(accessToken, tenantId); @@ -151,10 +152,9 @@ public class AppOrchestratorHandler { @ApiOperation(value = "Terminates application instance", response = String.class) @DeleteMapping(path = "/tenants/{tenant_id}/app_instances/{app_instance_id}", produces = MediaType.APPLICATION_JSON_VALUE) - @ApiResponses(value = { - @ApiResponse(code = 201, message = "request accepted ", response = String.class), - @ApiResponse(code = 500, message = "internal server error", response = String.class) - }) + @ApiResponses(value = {@ApiResponse(code = 201, message = "request accepted ", response = String.class), + @ApiResponse(code = 500, message = "internal server error", response = String.class) + }) public ResponseEntity terminateAppInstance( @ApiParam(value = "access token") @RequestHeader("access_token") String accessToken, @ApiParam(value = "tenant id") @PathVariable("tenant_id") @@ -174,10 +174,11 @@ public class AppOrchestratorHandler { */ @ApiOperation(value = "Retrieves edge host performance statistics", response = String.class) @GetMapping(path = "/tenants/{tenant_id}/hosts/{host_ip}/kpi", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity queryKpi( - @ApiParam(value = "access token") @RequestHeader("access_token") String accessToken, - @PathVariable("tenant_id") @Pattern(regexp = TENENT_ID_REGEX) String tenantId, - @ApiParam(value = "edge host ip") @PathVariable("host_ip") String hostIp) { + public ResponseEntity queryKpi(@ApiParam(value = "access token") + @RequestHeader("access_token") String accessToken, + @PathVariable("tenant_id") + @Pattern(regexp = TENENT_ID_REGEX) String tenantId, + @ApiParam(value = "edge host ip") @PathVariable("host_ip") String hostIp) { logger.debug("Query KPI request received..."); return appoService.queryKpi(accessToken, tenantId, hostIp); @@ -193,11 +194,12 @@ public class AppOrchestratorHandler { @ApiOperation(value = "Retrieves edge host platform capabilities", response = String.class) @GetMapping(path = "/tenants/{tenant_id}/hosts/{host_ip}/mep_capabilities", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity queryEdgehostCapabilities( - @ApiParam(value = "access token") @RequestHeader("access_token") String accessToken, - @ApiParam(value = "tenant id") @PathVariable("tenant_id") - @Pattern(regexp = TENENT_ID_REGEX) String tenantId, - @ApiParam(value = "edge host ip") @PathVariable("host_ip") String hostIp) { + public ResponseEntity queryEdgehostCapabilities(@ApiParam(value = "access token") + @RequestHeader("access_token") String accessToken, + @ApiParam(value = "tenant id") @PathVariable("tenant_id") + @Pattern(regexp = TENENT_ID_REGEX) String tenantId, + @ApiParam(value = "edge host ip") + @PathVariable("host_ip") String hostIp) { logger.debug("Query MEP capabilities request received..."); return appoService.queryEdgehostCapabilities(accessToken, tenantId, hostIp); -- Gitee From 9a25fb58ab9d6604a18f645d824e893b490bd47e Mon Sep 17 00:00:00 2001 From: "shashikanth.vh@huawei.com" Date: Fri, 28 Aug 2020 08:03:19 +0530 Subject: [PATCH 5/6] exception classes --- .../mecm/appo/exception/AppoException.java | 8 +++ .../appo/exception/AppoExceptionHandler.java | 61 +++++++++++++++++++ .../appo/exception/AppoExceptionResponse.java | 43 +++++++++++++ .../exception/AppoProcessflowException.java | 37 +++++++++++ 4 files changed, 149 insertions(+) create mode 100644 src/main/java/org/edgegallery/mecm/appo/exception/AppoException.java create mode 100644 src/main/java/org/edgegallery/mecm/appo/exception/AppoExceptionHandler.java create mode 100644 src/main/java/org/edgegallery/mecm/appo/exception/AppoExceptionResponse.java create mode 100644 src/main/java/org/edgegallery/mecm/appo/exception/AppoProcessflowException.java diff --git a/src/main/java/org/edgegallery/mecm/appo/exception/AppoException.java b/src/main/java/org/edgegallery/mecm/appo/exception/AppoException.java new file mode 100644 index 0000000..506e238 --- /dev/null +++ b/src/main/java/org/edgegallery/mecm/appo/exception/AppoException.java @@ -0,0 +1,8 @@ +package org.edgegallery.mecm.appo.exception; + +public class AppoException extends RuntimeException { + + public AppoException(String msg) { + super(msg); + } +} diff --git a/src/main/java/org/edgegallery/mecm/appo/exception/AppoExceptionHandler.java b/src/main/java/org/edgegallery/mecm/appo/exception/AppoExceptionHandler.java new file mode 100644 index 0000000..b4bcbf9 --- /dev/null +++ b/src/main/java/org/edgegallery/mecm/appo/exception/AppoExceptionHandler.java @@ -0,0 +1,61 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd. + * + * Licensed 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.edgegallery.mecm.appo.exception; + +import static org.edgegallery.mecm.appo.common.Constants.RECORD_NOT_FOUND; + +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.context.request.WebRequest; +import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; + +@ControllerAdvice +public class AppoExceptionHandler extends ResponseEntityExceptionHandler { + + @ExceptionHandler(value = AppoException.class) + public ResponseEntity exception(AppoException exception) { + return new ResponseEntity<>(exception.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } + + /** + * Exception handler for DB operations. + * + * @param exception exception + * @return return response + */ + @ExceptionHandler(value = AppoDbException.class) + public ResponseEntity exception(AppoDbException exception) { + if (exception.getMessage().equals(RECORD_NOT_FOUND)) { + return new ResponseEntity<>(exception.getMessage(), HttpStatus.NOT_FOUND); + } + return new ResponseEntity<>(exception.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } + + + @Override + protected ResponseEntity handleMethodArgumentNotValid(MethodArgumentNotValidException ex, + HttpHeaders headers, HttpStatus status, + WebRequest request) { + AppoExceptionResponse appoExceptionResponse = new AppoExceptionResponse("Validation Failed", + ex.getMessage()); + return new ResponseEntity(appoExceptionResponse, HttpStatus.BAD_REQUEST); + } +} diff --git a/src/main/java/org/edgegallery/mecm/appo/exception/AppoExceptionResponse.java b/src/main/java/org/edgegallery/mecm/appo/exception/AppoExceptionResponse.java new file mode 100644 index 0000000..1c1ab26 --- /dev/null +++ b/src/main/java/org/edgegallery/mecm/appo/exception/AppoExceptionResponse.java @@ -0,0 +1,43 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd. + * + * Licensed 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.edgegallery.mecm.appo.exception; + +public class AppoExceptionResponse { + + private String message; + private String details; + + /** + * Application exception response. + * + * @param message message + * @param details exception reason + */ + public AppoExceptionResponse(String message, String details) { + super(); + this.message = message; + this.details = details; + } + + public String getMessage() { + return message; + } + + public String getDetails() { + return details; + } +} \ No newline at end of file diff --git a/src/main/java/org/edgegallery/mecm/appo/exception/AppoProcessflowException.java b/src/main/java/org/edgegallery/mecm/appo/exception/AppoProcessflowException.java new file mode 100644 index 0000000..6527dfd --- /dev/null +++ b/src/main/java/org/edgegallery/mecm/appo/exception/AppoProcessflowException.java @@ -0,0 +1,37 @@ +/* + * Copyright 2020 Huawei Technologies Co., Ltd. + * + * Licensed 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.edgegallery.mecm.appo.exception; + +import org.edgegallery.mecm.appo.common.AppoProcessFlowResponse; + +public class AppoProcessflowException extends RuntimeException { + + AppoProcessFlowResponse appoProcessFlowResponse; + private int errorCode; + + public AppoProcessflowException(AppoProcessFlowResponse appoProcessFlowResponse) { + this.appoProcessFlowResponse = appoProcessFlowResponse; + } + + public AppoProcessFlowResponse getWorkflowResponse() { + return appoProcessFlowResponse; + } + + public Object getErrorCode() { + return errorCode; + } +} -- Gitee From f9bf37c0bed519fa9b746ad88f6f957b03164e3a Mon Sep 17 00:00:00 2001 From: "shashikanth.vh@huawei.com" Date: Fri, 28 Aug 2020 09:48:33 +0530 Subject: [PATCH 6/6] static tool issues fix --- .../apihandler/AppInstanceInfoHandler.java | 67 ++++++++----------- .../appo/service/AppInstanceInfoService.java | 13 ++-- 2 files changed, 34 insertions(+), 46 deletions(-) diff --git a/src/main/java/org/edgegallery/mecm/appo/apihandler/AppInstanceInfoHandler.java b/src/main/java/org/edgegallery/mecm/appo/apihandler/AppInstanceInfoHandler.java index 2f8a550..40de7b2 100644 --- a/src/main/java/org/edgegallery/mecm/appo/apihandler/AppInstanceInfoHandler.java +++ b/src/main/java/org/edgegallery/mecm/appo/apihandler/AppInstanceInfoHandler.java @@ -27,7 +27,6 @@ import java.util.List; import javax.validation.Valid; import javax.validation.constraints.Pattern; import org.edgegallery.mecm.appo.apihandler.dto.AppInstanceInfoDto; -import org.edgegallery.mecm.appo.exception.AppoDbException; import org.edgegallery.mecm.appo.model.AppInstanceInfo; import org.edgegallery.mecm.appo.service.AppInstanceInfoService; import org.modelmapper.ModelMapper; @@ -85,15 +84,12 @@ public class AppInstanceInfoHandler { @ApiParam(value = "application instance id") @PathVariable("appInstance_id") @Pattern(regexp = APP_INST_ID_REGX) String appInstanceId) { - AppInstanceInfo appInstanceInfo = null; - AppInstanceInfoDto dto = null; - try { - appInstanceInfo = appInstanceInfoService.getAppInstanceInfo(tenantId, appInstanceId); - ModelMapper mapper = new ModelMapper(); - dto = mapper.map(appInstanceInfo, AppInstanceInfoDto.class); - } catch (AppoDbException e) { - logger.debug("Query app instance info failed: {}", e.getMessage()); - } + logger.info("Retrieve application instance info: {}", appInstanceId); + + AppInstanceInfo appInstanceInfo = appInstanceInfoService.getAppInstanceInfo(tenantId, appInstanceId); + ModelMapper mapper = new ModelMapper(); + AppInstanceInfoDto dto = mapper.map(appInstanceInfo, AppInstanceInfoDto.class); + return new ResponseEntity<>(dto, HttpStatus.OK); } @@ -110,17 +106,16 @@ public class AppInstanceInfoHandler { @ApiParam(value = "access token") @RequestHeader("access_token") String accessToken, @ApiParam(value = "tenant id") @PathVariable("tenant_id") @Pattern(regexp = TENENT_ID_REGEX) String tenantId) { - List appInstanceInfos = null; + + logger.info("Retrieve application instance infos"); + List appInstanceInfosDto = new LinkedList<>(); - try { - appInstanceInfos = appInstanceInfoService.getAllAppInstanceInfo(tenantId); - for (AppInstanceInfo tenantAppInstanceInfo : appInstanceInfos) { - ModelMapper mapper = new ModelMapper(); - appInstanceInfosDto.add(mapper.map(tenantAppInstanceInfo, AppInstanceInfoDto.class)); - } - } catch (AppoDbException e) { - logger.debug("Query all app instance info failed: {}", e.getMessage()); + List appInstanceInfos = appInstanceInfoService.getAllAppInstanceInfo(tenantId); + for (AppInstanceInfo tenantAppInstanceInfo : appInstanceInfos) { + ModelMapper mapper = new ModelMapper(); + appInstanceInfosDto.add(mapper.map(tenantAppInstanceInfo, AppInstanceInfoDto.class)); } + return new ResponseEntity<>(appInstanceInfosDto, HttpStatus.OK); } @@ -139,15 +134,15 @@ public class AppInstanceInfoHandler { @ApiParam(value = "tenant id") @PathVariable("tenant_id") @Pattern(regexp = TENENT_ID_REGEX) String tenantId, @ApiParam(value = "application instance") @RequestBody AppInstanceInfoDto appInstInfoDto) { + + logger.info("Create application instance info: {}", appInstInfoDto.getAppInstanceId()); + ModelMapper mapper = new ModelMapper(); AppInstanceInfo appInstanceInfo = mapper.map(appInstInfoDto, AppInstanceInfo.class); - AppInstanceInfoDto dto = null; - try { - appInstanceInfo = appInstanceInfoService.createAppInstanceInfo(tenantId, appInstanceInfo); - dto = mapper.map(appInstanceInfo, AppInstanceInfoDto.class); - } catch (AppoDbException e) { - logger.debug("Create app instance info failed: {}", e.getMessage()); - } + + appInstanceInfo = appInstanceInfoService.createAppInstanceInfo(tenantId, appInstanceInfo); + + AppInstanceInfoDto dto = mapper.map(appInstanceInfo, AppInstanceInfoDto.class); return new ResponseEntity<>(dto, HttpStatus.OK); } @@ -168,11 +163,8 @@ public class AppInstanceInfoHandler { @ApiParam(value = "application instance id") @PathVariable("appInstance_id") @Pattern(regexp = APP_INST_ID_REGX) String appInstanceId) { - try { - appInstanceInfoService.deleteAppInstanceInfo(tenantId, appInstanceId); - } catch (AppoDbException e) { - logger.debug("Delete app instance info failed: {}", e.getMessage()); - } + logger.info("Delete application instance info: {}", appInstanceId); + appInstanceInfoService.deleteAppInstanceInfo(tenantId, appInstanceId); return new ResponseEntity<>("success", HttpStatus.OK); } @@ -196,16 +188,15 @@ public class AppInstanceInfoHandler { @Pattern(regexp = APP_INST_ID_REGX) String appInstanceId, @ApiParam(value = "application instance") @Valid @RequestBody AppInstanceInfoDto instInfo) { + logger.info("Update application instance info: {}", instInfo.getAppInstanceId()); + ModelMapper mapper = new ModelMapper(); AppInstanceInfo appInstanceInfo = mapper.map(instInfo, AppInstanceInfo.class); appInstanceInfo.setAppInstanceId(appInstanceId); - AppInstanceInfoDto dto = null; - try { - appInstanceInfo = appInstanceInfoService.updateAppInstanceInfo(tenantId, appInstanceInfo); - dto = mapper.map(appInstanceInfo, AppInstanceInfoDto.class); - } catch (AppoDbException e) { - logger.debug("Update app instance info failed: {}", e.getMessage()); - } + + appInstanceInfo = appInstanceInfoService.updateAppInstanceInfo(tenantId, appInstanceInfo); + AppInstanceInfoDto dto = mapper.map(appInstanceInfo, AppInstanceInfoDto.class); + return new ResponseEntity<>(dto, HttpStatus.OK); } } \ No newline at end of file diff --git a/src/main/java/org/edgegallery/mecm/appo/service/AppInstanceInfoService.java b/src/main/java/org/edgegallery/mecm/appo/service/AppInstanceInfoService.java index 537b3af..17d4d3e 100644 --- a/src/main/java/org/edgegallery/mecm/appo/service/AppInstanceInfoService.java +++ b/src/main/java/org/edgegallery/mecm/appo/service/AppInstanceInfoService.java @@ -1,7 +1,6 @@ package org.edgegallery.mecm.appo.service; import java.util.List; -import org.edgegallery.mecm.appo.exception.AppoDbException; import org.edgegallery.mecm.appo.model.AppInstanceInfo; public interface AppInstanceInfoService { @@ -13,7 +12,7 @@ public interface AppInstanceInfoService { * @param appInstanceId application instance ID * @return application instance information */ - AppInstanceInfo getAppInstanceInfo(String tenantId, String appInstanceId) throws AppoDbException; + AppInstanceInfo getAppInstanceInfo(String tenantId, String appInstanceId); /** * Retrieves all application instance information. @@ -21,7 +20,7 @@ public interface AppInstanceInfoService { * @param tenantId tenant ID * @return application instance information */ - List getAllAppInstanceInfo(String tenantId) throws AppoDbException; + List getAllAppInstanceInfo(String tenantId); /** * Creates application instance info. @@ -30,8 +29,7 @@ public interface AppInstanceInfoService { * @param appInstanceInfo application information * @return application information */ - AppInstanceInfo createAppInstanceInfo(String tenantId, - AppInstanceInfo appInstanceInfo) throws AppoDbException; + AppInstanceInfo createAppInstanceInfo(String tenantId, AppInstanceInfo appInstanceInfo); /** * Deletes application instance information. @@ -39,7 +37,7 @@ public interface AppInstanceInfoService { * @param tenantId tenant ID * @param appInstanceId application instance ID */ - void deleteAppInstanceInfo(String tenantId, String appInstanceId) throws AppoDbException; + void deleteAppInstanceInfo(String tenantId, String appInstanceId); /** * Updates application instance info. @@ -48,6 +46,5 @@ public interface AppInstanceInfoService { * @param appInstanceInfo application information * @return application information */ - AppInstanceInfo updateAppInstanceInfo(String tenantId, - AppInstanceInfo appInstanceInfo) throws AppoDbException; + AppInstanceInfo updateAppInstanceInfo(String tenantId, AppInstanceInfo appInstanceInfo); } -- Gitee