Skip to content

Commit

Permalink
Merge 10a0be9 into 3edca80
Browse files Browse the repository at this point in the history
  • Loading branch information
wujimin committed Aug 9, 2018
2 parents 3edca80 + 10a0be9 commit e067e1a
Show file tree
Hide file tree
Showing 13 changed files with 212 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public void afterRegistryInstance(MicroserviceInstanceRegisterTask microserviceI
status = SCBStatus.UP;
triggerEvent(EventType.AFTER_REGISTRY);
EventManager.unregister(this);
LOGGER.info("ServiceComb is ready.");
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Response afterReceiveResponse(Invocation invocation, HttpServletResponseE
String serverSignature = responseEx.getHeader("signature");

if (serverSignature != null) {
LOGGER.info("check response signature, client: {}, server: {}.", signature, serverSignature);
LOGGER.debug("check response signature, client: {}, server: {}.", signature, serverSignature);
if (!signature.equals(serverSignature)) {
LOGGER.error("check response signature failed");
return Response.create(Status.UNAUTHORIZED, "check response signature failed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public boolean needCacheRequest(OperationMeta operationMeta) {
public Response afterReceiveRequest(Invocation invocation, HttpServletRequestEx requestEx) {
String signature = SignatureUtils.genSignature(requestEx);
String clientSignature = requestEx.getHeader("signature");
LOGGER.info("check request signature, client: {}, server: {}.", clientSignature, signature);
LOGGER.debug("check request signature, client: {}, server: {}.", clientSignature, signature);
if (!signature.equals(clientSignature)) {
LOGGER.error("check request signature failed: {}", invocation.getInvocationQualifiedName());
return Response
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/it-common/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<pattern>%d [%level] [%thread] - %msg (%F:%L\)%n</pattern>
</encoder>
</appender>
<root level="WARN">
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ public class ConsumerMain {
public static boolean autoExit = true;

public static void main(String[] args) throws Throwable {
deploys.init();
deploys.getServiceCenter().ensureReady();

BeanUtils.init();
ITUtils.waitBootFinished();

deploys.init();
run();

SCBEngine.getInstance().destroy();
deploys.getServiceCenter().stop();

resultPrinter.print();

if (autoExit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public class DeployDefinition {

protected String displayName;

protected String startCompleteLog;

protected String workDir;

/**
* <pre>
* edge as the example:
Expand Down Expand Up @@ -57,6 +61,22 @@ public void setDisplayName(String displayName) {
this.displayName = displayName;
}

public String getStartCompleteLog() {
return startCompleteLog;
}

public void setStartCompleteLog(String startCompleteLog) {
this.startCompleteLog = startCompleteLog;
}

public String getWorkDir() {
return workDir;
}

public void setWorkDir(String workDir) {
this.workDir = workDir;
}

public String getCmd() {
return cmd;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ public class Deploys {

private String pomVersion;

public MicroserviceDeploy edge;
private ServiceCenterDeploy serviceCenter;

public MicroserviceDeploy baseProducer;
private MicroserviceDeploy edge;

public MicroserviceDeploy zuul;
private MicroserviceDeploy baseProducer;

private MicroserviceDeploy zuul;

public ServiceCenterDeploy getServiceCenter() {
return serviceCenter;
}

public MicroserviceDeploy getEdge() {
return edge;
Expand All @@ -54,6 +60,7 @@ public void init() throws Throwable {
initPomVersion();
LOGGER.info("test version: {}", pomVersion);

serviceCenter = new ServiceCenterDeploy();
initEdge();
initBaseProducer();
// initZuul();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.servicecomb.it.deploy;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.servicecomb.it.ITUtils;
import org.apache.servicecomb.serviceregistry.RegistryUtils;
import org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersionRule;
Expand All @@ -30,18 +31,21 @@ public class MicroserviceDeploy extends NormalDeploy {
public MicroserviceDeploy(DeployDefinition deployDefinition) {
super(deployDefinition);
this.microserviceDeployDefinition = (MicroserviceDeployDefinition) deployDefinition;
}

@Override
public void deploy() throws Throwable {
super.deploy();
this.microserviceDeployDefinition.setStartCompleteLog("ServiceComb is ready.");
}

@Override
protected String[] createCmds() {
return new String[] {"java", "-jar", deployDefinition.getCmd()};
}

@Override
protected String[] addArgs(String[] cmds) {
return ArrayUtils.addAll(super.addArgs(cmds),
"-DselfController=" + RegistryUtils.getMicroserviceInstance().getInstanceId());
}

public void ensureReady() throws Throwable {
MicroserviceVersionRule microserviceVersionRule = RegistryUtils.getServiceRegistry().getAppManager()
.getOrCreateMicroserviceVersionRule(microserviceDeployDefinition.getAppId(),
Expand All @@ -53,6 +57,7 @@ public void ensureReady() throws Throwable {
}

deploy();
waitStartComplete();
ITUtils.waitMicroserviceReady(microserviceDeployDefinition.getAppId(),
microserviceDeployDefinition.getMicroserviceName(),
microserviceDeployDefinition.getVersion(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@


import java.io.BufferedWriter;
import java.io.File;
import java.io.OutputStreamWriter;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.servicecomb.foundation.common.utils.JsonUtils;
import org.apache.servicecomb.serviceregistry.RegistryUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -44,21 +44,33 @@ public NormalDeploy(DeployDefinition deployDefinition) {

public void deploy() throws Throwable {
String[] cmds = createCmds();
cmds = ArrayUtils.addAll(cmds, deployDefinition.getArgs());
cmds = ArrayUtils.addAll(cmds,
"-DselfController=" + RegistryUtils.getMicroserviceInstance().getInstanceId());
cmds = addArgs(cmds);

subProcess = createProcessBuilder(cmds).start();
subProcessCommandWriter = new BufferedWriter(new OutputStreamWriter(subProcess.getOutputStream()));
subProcessLogger = new SubProcessLogger(deployDefinition.getDisplayName(), subProcess.getInputStream());
subProcessLogger = new SubProcessLogger(deployDefinition.getDisplayName(), subProcess.getInputStream(),
deployDefinition.getStartCompleteLog());
}

protected String[] addArgs(String[] cmds) {
cmds = ArrayUtils.addAll(cmds, deployDefinition.getArgs());
return cmds;
}

protected String[] createCmds() {
return new String[] {deployDefinition.getCmd()};
}

protected ProcessBuilder createProcessBuilder(String[] cmds) {
return new ProcessBuilder(cmds).redirectErrorStream(true);
ProcessBuilder processBuilder = new ProcessBuilder(cmds).redirectErrorStream(true);
if (deployDefinition.getWorkDir() != null) {
processBuilder.directory(new File(deployDefinition.getWorkDir()));
}
return processBuilder;
}

public void waitStartComplete() {
subProcessLogger.waitStartComplete();
}

public void sendCommand(Object command) {
Expand All @@ -82,7 +94,7 @@ protected void afterStop() {

public void waitStop() {
if (subProcess == null) {
LOGGER.info("Ignore, already stop, displayName={}.", deployDefinition.getDisplayName());
LOGGER.info("Ignore, already stop or reusing exist instance, displayName={}.", deployDefinition.getDisplayName());
return;
}

Expand All @@ -98,17 +110,18 @@ public void waitStop() {
subProcess = null;
afterStop();

LOGGER.info("finished stop {}.", deployDefinition.getDisplayName());
LOGGER.info("stop complete, displayName={}.", deployDefinition.getDisplayName());
}

public void stop() {
if (subProcess == null) {
LOGGER.info("Ignore, already stop, displayName={}.", deployDefinition.getDisplayName());
LOGGER.info("Ignore, already stop or reusing exist instance, displayName={}.", deployDefinition.getDisplayName());
return;
}

subProcess.destroy();
subProcess = null;
afterStop();
LOGGER.info("stop complete, displayName={}.", deployDefinition.getDisplayName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* 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
*
* 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.apache.servicecomb.it.deploy;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.servicecomb.serviceregistry.api.registry.ServiceCenterInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.client.RestTemplate;

import io.swagger.util.Json;

public class ServiceCenterDeploy extends NormalDeploy {
private static final Logger LOGGER = LoggerFactory.getLogger(ServiceCenterDeploy.class);

public ServiceCenterDeploy() {
super(new DeployDefinition());

deployDefinition.setDeployName("serviceCenter");
deployDefinition.setDisplayName("serviceCenter");
if (SystemUtils.IS_OS_WINDOWS) {
deployDefinition.setCmd("service-center.exe");
} else {
deployDefinition.setCmd("service-center");
}
deployDefinition.setStartCompleteLog("server is ready");
}

public void ensureReady() throws Throwable {
// check if is running
// {"version":"1.0.0","buildTag":"20180608145515.1.0.0.b913a2d","runMode":"dev","apiVersion":"3.0.0"}
try {
String address = "http://localhost:30100/version";
ServiceCenterInfo serviceCenterInfo = new RestTemplate().getForObject(address, ServiceCenterInfo.class);
if (serviceCenterInfo != null && serviceCenterInfo.getVersion() != null) {
LOGGER.info("{} already started, {}.", deployDefinition.getDisplayName(), Json.pretty(serviceCenterInfo));
return;
}
} catch (Throwable e) {
LOGGER.info("failed to get ServiceCenter version, message={}", e.getMessage());
}

initServiceCenterCmd();
LOGGER.info("definition of {} is: {}", deployDefinition.getDeployName(), deployDefinition);

deploy();
waitStartComplete();
}

protected void initServiceCenterCmd() throws IOException {
// where is service center
// 1.find from env, for local dev environment
LOGGER.info("try to find serviceCenter by env {}.", "serviceCenterHome");
String dir = System.getenv("serviceCenterHome");
if (dir != null) {
LOGGER.info("serviceCenterHome={}.", dir);
File file = new File(dir, deployDefinition.getCmd());
if (file.exists()) {
FileUtils.cleanDirectory(new File(dir, "data"));
deployDefinition.setWorkDir(dir);
deployDefinition.setCmd(file.getAbsolutePath());
return;
}

LOGGER.info("{} is not exist.", file.getAbsolutePath());
}

// 2.docker, for CI environment
LOGGER.info("can not find serviceCenter by env {}, try run by docker.", "serviceCenterHome");
deployDefinition.setCmd("docker");
deployDefinition.setArgs(new String[] {
"run",
"-p",
"127.0.0.1:30100:30100",
"servicecomb/service-center"
});
}
}

0 comments on commit e067e1a

Please sign in to comment.