Added Deployment Files
[eliot.git] / blueprints / common / eliot-ui / be / src / eliotk8sclient / src / main / java / com / eliot / eliotbe / eliotk8sclient / controller / AppDeployController.java
1 /*
2  * Copyright 2020 Huawei Technologies Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.eliot.eliotbe.eliotk8sclient.controller;
18
19 import com.eliot.eliotbe.eliotk8sclient.service.AppServiceHandler;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22 import org.springframework.beans.factory.annotation.Autowired;
23 import org.springframework.http.MediaType;
24 import org.springframework.http.ResponseEntity;
25 import org.springframework.validation.annotation.Validated;
26 import org.springframework.web.bind.annotation.*;
27 import org.springframework.web.multipart.MultipartFile;
28
29 import javax.validation.constraints.Pattern;
30 import java.io.IOException;
31 import java.util.List;
32 import java.util.Map;
33
34 @Validated
35 @RestController
36 public class AppDeployController {
37
38     public static final Logger logger = LoggerFactory.getLogger(AppDeployController.class);
39
40     public static final String HOST_IP_REGEXP
41         = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$";
42     public static final String APP_INSTANCE_ID_REGEXP
43             = "([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}){1}";
44     public static final String TENENT_ID_REGEXP = "[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}";
45     public static final String WORKLOAD_ID_REGEXP = "^.{1,1024}$";
46     public static final String QUERY_REGEXP = "^.{1,512}$";
47     @Autowired
48     private AppServiceHandler appServiceHandler;
49
50     /**
51      * Upload Deployment YAML file.
52      * @param file file
53      * @return
54      */
55     @RequestMapping(path = "/upload",
56         method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
57     public ResponseEntity<Map<String, String>> uploadAppDeployment(
58             @RequestParam("file") MultipartFile file) throws IOException {
59         logger.info("Deployment Upload File");
60         return appServiceHandler.uploadDeployment(file);
61     }
62 }