-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #504 from WeBankBlockchain/lab-dev
merge 3.1.0 master
- Loading branch information
Showing
23 changed files
with
626 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
src/main/java/com/webank/webase/node/mgr/contract/scaffold/ScaffoldController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/** | ||
* Copyright 2014-2020 the original author or authors. | ||
* <p> | ||
* 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 | ||
* <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 com.webank.webase.node.mgr.contract.scaffold; | ||
|
||
import com.webank.webase.node.mgr.base.code.ConstantCode; | ||
import com.webank.webase.node.mgr.base.controller.BaseController; | ||
import com.webank.webase.node.mgr.base.entity.BaseResponse; | ||
import com.webank.webase.node.mgr.base.exception.NodeMgrException; | ||
import com.webank.webase.node.mgr.config.properties.ConstantProperties; | ||
import com.webank.webase.node.mgr.contract.scaffold.entity.ReqProject; | ||
import com.webank.webase.node.mgr.contract.scaffold.entity.RspFile; | ||
import com.webank.webase.node.mgr.tools.IPUtil; | ||
import com.webank.webase.node.mgr.tools.NodeMgrTools; | ||
import com.webank.webase.node.mgr.tools.ValidateUtil; | ||
import java.time.Duration; | ||
import java.time.Instant; | ||
import javax.validation.Valid; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* @author marsli | ||
*/ | ||
@Log4j2 | ||
@RestController | ||
@RequestMapping(value = "scaffold") | ||
public class ScaffoldController extends BaseController { | ||
@Autowired | ||
private ScaffoldService scaffoldService; | ||
|
||
@PostMapping("/export") | ||
@PreAuthorize(ConstantProperties.HAS_ROLE_ADMIN_OR_DEVELOPER) | ||
public BaseResponse exportProjectApi(@Valid @RequestBody ReqProject param) { | ||
Instant startTime = Instant.now(); | ||
log.info("start exportProjectApi param:{} groupId:{}", startTime.toEpochMilli(), | ||
param); | ||
if (StringUtils.isBlank(param.getChannelIp())) { | ||
param.setChannelIp(IPUtil.LOCAL_IP_127); | ||
} | ||
// check artifact name and group name | ||
if (!NodeMgrTools.startWithLetter(param.getArtifactName())) { | ||
log.error("must start with letter"); | ||
throw new NodeMgrException(ConstantCode.PARAM_INVALID_LETTER_DIGIT); | ||
} | ||
// validate group name, ex: org.example | ||
if (!param.getGroup().contains(".")) { | ||
// only org | ||
if (!NodeMgrTools.startWithLetter(param.getGroup())) { | ||
log.error("group must start with letter"); | ||
throw new NodeMgrException(ConstantCode.PARAM_INVALID_LETTER_DIGIT); | ||
} | ||
} else { | ||
// include org.xxx | ||
String[] groupNameArray = param.getGroup().split("\\."); | ||
for (String group: groupNameArray) { | ||
// not start or end with dot "." | ||
if (StringUtils.isBlank(group)) { | ||
log.error("group must start with letter, and not end with dot"); | ||
throw new NodeMgrException(ConstantCode.PARAM_INVALID_LETTER_DIGIT); | ||
} | ||
if (!NodeMgrTools.startWithLetter(group)) { | ||
log.error("group name must start with letter"); | ||
throw new NodeMgrException(ConstantCode.PARAM_INVALID_LETTER_DIGIT); | ||
} | ||
} | ||
} | ||
RspFile rspFile = scaffoldService.exportProject(param); | ||
log.info("end exportProjectApi useTime:{} result:{}", | ||
Duration.between(startTime, Instant.now()).toMillis(), rspFile); | ||
return new BaseResponse(ConstantCode.SUCCESS, rspFile); | ||
} | ||
|
||
|
||
@GetMapping("/check") | ||
public BaseResponse checkChannelPort(@RequestParam("nodeIp") String nodeIp, | ||
@RequestParam("channelPort") int channelPort) { | ||
Instant startTime = Instant.now(); | ||
log.info("start checkChannelPort startTime:{}, nodeIp:{} channelPort:{}", | ||
startTime.toEpochMilli(), nodeIp, channelPort); | ||
if(!ValidateUtil.ipv4Valid(nodeIp)) { | ||
log.error("not valid nodeIp:{}", nodeIp); | ||
throw new NodeMgrException(ConstantCode.IP_FORMAT_ERROR); | ||
} | ||
Boolean result = scaffoldService.telnetChannelPort(nodeIp, channelPort); | ||
|
||
log.info("end exportProjectApi useTime:{} result:{}", | ||
Duration.between(startTime, Instant.now()).toMillis(), result); | ||
return new BaseResponse(ConstantCode.SUCCESS, result); | ||
} | ||
} |
Oops, something went wrong.