() {
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
CodeLoadService.changeClassLoader(event.getEnvironment());
}
});
springApplication.run(args);
}
@Bean
public WebMvcConfigurer webMvcConfigurer() {
return new WebMvcConfigurerAdapter() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/api/**").allowedMethods("GET", "POST", "PUT", "DELETE");
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
super.addResourceHandlers(registry);
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
}
};
}
@Bean
public ExitCodeGenerator exitCodeGenerator() {
return new ExitCodeGenerator() {
@Override
public int getExitCode() {
return 0;
}
};
}
@Override
public void run(String... args) throws Exception {
// handle the command
Boolean webEnv = false;
if (applicationArguments.containsOption(ConsoleConstants.OPTION_ADMIN)) {
webEnv = true;
}
if (!webEnv) {
menuOptionHandler.handleMenuOption();
}
}
}
================================================
FILE: tac-console/src/main/java/com/alibaba/tac/console/ConsoleBeanConfig.java
================================================
/*
* MIT License
*
* Copyright (c) 2016 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.alibaba.tac.console;
import com.alibaba.tac.engine.service.EngineBeansConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.*;
/**
* @author jinshuan.li 01/03/2018 17:21
*
* this class is used to scan extend packages you can set the scan.package.name value from properties
*/
@Slf4j
@ConditionalOnProperty(name = "scan.package.name")
@Configuration
@ComponentScan(basePackages = "${scan.package.name}")
@Import(EngineBeansConfig.class)
public class ConsoleBeanConfig {
}
================================================
FILE: tac-console/src/main/java/com/alibaba/tac/console/ConsoleConstants.java
================================================
/*
* MIT License
*
* Copyright (c) 2016 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.alibaba.tac.console;
/**
* @author jinshuan.li 27/02/2018 21:00
*/
public class ConsoleConstants {
public static final String MENU_HELP = "help";
public static final String MENU_PACKAGE = "package";
public static final String MENU_PUBLISH = "publish";
public static final String OPTION_ADMIN = "admin";
public static final String ADDDITION_PROFILE_SIMPLE = "simple";
public static final String ADDDITION_PROFILE_ADMIN = "admin";
public static final String ADDDITION_PROFILE_CONSOLE = "debug";
}
================================================
FILE: tac-console/src/main/java/com/alibaba/tac/console/TacApplicationContext.java
================================================
/*
* MIT License
*
* Copyright (c) 2016 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.alibaba.tac.console;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext;
/**
* @author jinshuan.li 06/03/2018 20:51
*/
@Slf4j
@Deprecated
public class TacApplicationContext extends AnnotationConfigEmbeddedWebApplicationContext {
public TacApplicationContext() throws Exception {
super();
}
}
================================================
FILE: tac-console/src/main/java/com/alibaba/tac/console/error/ConsoleError.java
================================================
/*
* MIT License
*
* Copyright (c) 2016 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.alibaba.tac.console.error;
/**
* @author jinshuan.li 06/03/2018 12:19
*/
public enum ConsoleError implements IErrorCode {
/**
* system error
*/
SYSTEM_ERROR("SYSTEM_ERROR", "system error");
private ConsoleError(String code, String msg) {
this.code = code;
this.msg = msg;
}
private String code;
private String msg;
@Override
public String getCode() {
return code;
}
@Override
public String getMessage() {
return msg;
}
}
================================================
FILE: tac-console/src/main/java/com/alibaba/tac/console/error/IErrorCode.java
================================================
/*
* MIT License
*
* Copyright (c) 2016 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.alibaba.tac.console.error;
/**
* @author jinshuan.li 06/03/2018 12:18
*/
public interface IErrorCode {
String getCode();
String getMessage();
}
================================================
FILE: tac-console/src/main/java/com/alibaba/tac/console/sdk/MenuOptionHandler.java
================================================
/*
* MIT License
*
* Copyright (c) 2016 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.alibaba.tac.console.sdk;
import com.alibaba.tac.console.ConsoleConstants;
import com.alibaba.tac.engine.code.CodeCompileService;
import com.alibaba.tac.engine.code.TacFileService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.boot.ApplicationArguments;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.List;
/**
* @author jinshuan.li 27/02/2018 21:05
*/
@Slf4j
@Service
public class MenuOptionHandler {
@Resource
private ApplicationArguments arguments;
@Resource
private CodeCompileService codeCompileService;
@Resource
private TacFileService tacFileService;
@PostConstruct
public void init() {
}
/**
* handle the menu option
*
* the is just a package command
*
* @throws IOException
*/
public void handleMenuOption() throws IOException {
if (CollectionUtils.isEmpty(arguments.getOptionNames())) {
printUsage();
return;
}
if (arguments.containsOption(ConsoleConstants.MENU_PACKAGE)) {
System.out.println("handleo pacakge");
handlePackage();
}
if (arguments.containsOption(ConsoleConstants.MENU_PUBLISH)) {
//handlePublish();
}
}
/**
* handle compile and package source
*/
protected void handlePackage() {
String msCode = "";
List msCodes = arguments.getOptionValues("msCode");
List srcDirs = arguments.getOptionValues("sourceDir");
if (CollectionUtils.isEmpty(msCodes)) {
printUsage();
return;
}
msCode = msCodes.get(0);
String srcDir = "";
if (CollectionUtils.isEmpty(srcDirs)) {
String absolutePath = new File("").getAbsolutePath();
srcDir = absolutePath;
} else {
srcDir = srcDirs.get(0);
}
try {
// compile
Boolean compile = codeCompileService.compile(msCode, srcDir);
// package
codeCompileService.getJarFile(msCode);
log.info("package success . file:{}", tacFileService.getClassFileOutputPath(msCode) + ".zip");
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
public static void printUsage() {
System.out.println("useage:");
System.out.println("--package --msCode=${msCode} --sourceDir=${sourceDir}");
// System.out.println("--publish --msCode=${msCode} --zipFile=${zipFile}");
}
}
================================================
FILE: tac-console/src/main/java/com/alibaba/tac/console/web/HomeController.java
================================================
/*
* MIT License
*
* Copyright (c) 2016 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.alibaba.tac.console.web;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @author jinshuan.li 07/03/2018 17:18
*/
@Controller
@RequestMapping
public class HomeController {
@GetMapping("/")
public String index() {
return "index";
}
}
================================================
FILE: tac-console/src/main/java/com/alibaba/tac/console/web/InstFileRO.java
================================================
/*
* MIT License
*
* Copyright (c) 2016 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.alibaba.tac.console.web;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
import java.io.Serializable;
/**
* @author jinshuan.li 05/03/2018 20:16
*/
@Data
public class InstFileRO implements Serializable{
private static final long serialVersionUID = -7650755238417075767L;
private String name;
private MultipartFile file;
private Integer age;
}
================================================
FILE: tac-console/src/main/java/com/alibaba/tac/console/web/TacInstController.java
================================================
/*
* MIT License
*
* Copyright (c) 2016 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.alibaba.tac.console.web;
import com.alibaba.tac.console.error.ConsoleError;
import com.alibaba.tac.console.web.ro.InstTestRO;
import com.alibaba.tac.engine.inst.domain.TacInst;
import com.alibaba.tac.engine.inst.service.IMsInstFileService;
import com.alibaba.tac.engine.inst.service.IMsInstService;
import com.alibaba.tac.engine.ms.domain.TacMsDO;
import com.alibaba.tac.engine.ms.service.IMsPublisher;
import com.alibaba.tac.engine.ms.service.IMsService;
import com.alibaba.tac.engine.service.TacPublishTestService;
import com.alibaba.tac.engine.code.TacFileService;
import com.alibaba.tac.sdk.common.TacResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* @author jinshuan.li 05/03/2018 20:14
*/
@Slf4j
@RestController
@RequestMapping("/api/inst")
public class TacInstController {
@Resource
private IMsService msService;
@Resource
private IMsInstService msInstService;
@Resource
private IMsPublisher msPublisher;
@Resource
private TacPublishTestService tacPublishTestService;
@Resource(name = "prePublishMsInstFileService")
private IMsInstFileService prePublishMsInstFileService;
@PostMapping(value = "/uploadFile")
public TacResult> uploadFile(@RequestParam("file") MultipartFile instFileRO,
@RequestParam("msCode") String msCode) {
return TacResult.newResult(null);
}
@GetMapping(value = "/info/{msCode}")
public TacResult getMsInst(@PathVariable("msCode") String msCode) {
try {
TacMsDO ms = msService.getMs(msCode);
if (ms == null) {
throw new IllegalArgumentException("the service is not exist");
}
TacInst tacInst = this.getExistTacInst(ms, "");
return TacResult.newResult(tacInst);
} catch (Exception e) {
return TacResult.errorResult(ConsoleError.SYSTEM_ERROR.getCode(), e.getMessage());
}
}
@PostMapping("/create")
public TacResult create(@RequestBody TacInst tacInst) {
String msCode = tacInst.getMsCode();
try {
if (StringUtils.isEmpty(msCode)) {
throw new IllegalArgumentException("invalid params");
}
TacMsDO ms = msService.getMs(msCode);
if (ms == null) {
throw new IllegalStateException("the service with code " + msCode + " not exist");
}
String name = tacInst.getName();
String gitBranch = tacInst.getGitBranch();
if (StringUtils.isEmpty(name) || StringUtils.isEmpty(gitBranch)) {
throw new IllegalArgumentException("invalid params");
}
msInstService.createGitTacMsInst(msCode, name, gitBranch);
return TacResult.newResult(ms);
} catch (Exception e) {
return TacResult.errorResult(ConsoleError.SYSTEM_ERROR.getCode(), e.getMessage());
}
}
@PostMapping("/update")
public TacResult update(@RequestBody TacInst tacInst) {
String msCode = tacInst.getMsCode();
long instId = tacInst.getId();
try {
if (StringUtils.isEmpty(msCode)) {
throw new IllegalArgumentException("invalid params");
}
TacMsDO ms = msService.getMs(msCode);
if (ms == null) {
throw new IllegalStateException("the service with code " + msCode + " not exist");
}
TacInst tacMsInst = msInstService.getTacMsInst(instId);
if (tacMsInst == null) {
throw new IllegalStateException("inst not exist");
}
String name = tacInst.getName();
String gitBranch = tacInst.getGitBranch();
if (StringUtils.isEmpty(name) || StringUtils.isEmpty(gitBranch)) {
throw new IllegalArgumentException("invalid params");
}
tacMsInst.setGitBranch(gitBranch);
tacMsInst.setName(name);
msInstService.updateTacMsInst(instId, tacMsInst);
return TacResult.newResult(ms);
} catch (Exception e) {
return TacResult.errorResult(ConsoleError.SYSTEM_ERROR.getCode(), e.getMessage());
}
}
@GetMapping(value = "/list/{msCode}")
public TacResult> getMsInstList(@PathVariable("msCode") String msCode) {
try {
TacMsDO ms = msService.getMs(msCode);
if (ms == null) {
throw new IllegalArgumentException("the service is not exist");
}
List msInsts = msInstService.getMsInsts(msCode);
Optional.ofNullable(msInsts).ifPresent(items -> {
items.stream().forEach(d -> {
if (d.getStatus() == null) {
d.setStatus(TacInst.STATUS_NEW);
}
});
});
return TacResult.newResult(msInsts);
} catch (Exception e) {
return TacResult.errorResult(ConsoleError.SYSTEM_ERROR.getCode(), e.getMessage());
}
}
private TacInst getExistTacInst(TacMsDO ms, String jarVersion) {
String msCode = ms.getCode();
Long publishedInstId = ms.getPublishedInstId();
TacInst tacMsInst = null;
if (publishedInstId == null || publishedInstId.equals(0)) {
tacMsInst = msInstService.createTacMsInst(msCode, ms.getName(), jarVersion);
// update service data
ms.setPublishedInstId(tacMsInst.getId());
msService.updateMs(msCode, ms);
publishedInstId = ms.getPublishedInstId();
}
tacMsInst = msInstService.getTacMsInst(publishedInstId);
if (tacMsInst == null) {
throw new IllegalStateException("can't find the instance " + publishedInstId);
}
return tacMsInst;
}
@PostMapping(value = "/prePublish")
public TacResult prePublish(@RequestParam("file") MultipartFile instFileRO,
@RequestParam("msCode") String msCode,
@RequestParam(value = "instId", required = false) Long instId) {
try {
byte[] bytes = instFileRO.getBytes();
String md5 = TacFileService.getMd5(bytes);
TacMsDO ms = msService.getMs(msCode);
if (ms == null) {
throw new IllegalArgumentException("the service is not exist");
}
TacInst tacMsInst = this.getExistTacInst(ms, md5);
// prepublish
msPublisher.prePublish(tacMsInst, bytes);
return TacResult.newResult(msInstService.getTacMsInst(tacMsInst.getId()));
} catch (Exception e) {
return TacResult.errorResult(ConsoleError.SYSTEM_ERROR.getCode(), e.getMessage());
}
}
@PostMapping(value = "/publish")
public TacResult publish(@RequestParam("msCode") String msCode,
@RequestParam(value = "instId") Long instId) {
try {
TacInst tacMsInst = msInstService.getTacMsInst(instId);
if (tacMsInst == null) {
throw new IllegalArgumentException("the instance is not exist " + instId);
}
if (!StringUtils.equalsIgnoreCase(tacMsInst.getMsCode(), msCode)) {
throw new IllegalArgumentException("the msCode is not match");
}
// 取预发布的数据
byte[] instanceFile = prePublishMsInstFileService.getInstanceFile(instId);
if (instanceFile == null) {
throw new IllegalStateException("can't find prePublish data");
}
// 正式发布
msPublisher.publish(tacMsInst, instanceFile);
} catch (Exception e) {
return TacResult.errorResult(ConsoleError.SYSTEM_ERROR.getCode(), e.getMessage());
}
return TacResult.newResult(null);
}
@PostMapping(value = "/preTest")
public TacResult