Skip to content

Commit

Permalink
Merge pull request #17 from koupleless/youji-dev
Browse files Browse the repository at this point in the history
support start with args and envs
  • Loading branch information
lvjing2 authored Mar 27, 2024
2 parents 5d5dbac + f157102 commit ece024e
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 10 deletions.
6 changes: 6 additions & 0 deletions arklet-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
<groupId>com.alipay.sofa.koupleless</groupId>
<artifactId>koupleless-common</artifactId>
<version>${revision}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</exclusion>
</exclusions>
</dependency>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.lang.management.MemoryPoolMXBean;
import java.net.URL;
import java.util.List;
import java.util.Map;

/**
* @author mingmen
Expand All @@ -61,7 +62,8 @@ public Output<InstallBizClientResponse> handle(Input input) {
long startSpace = metaSpaceMXBean.getUsage().getUsed();
try {
InstallBizClientResponse installBizClientResponse = convertClientResponse(getOperationService()
.install(input.getBizUrl()));
.install(input.getBizName(), input.getBizVersion(), input.getBizUrl(),
input.getArgs(), input.getEnvs()));
installBizClientResponse.setElapsedSpace(metaSpaceMXBean.getUsage().getUsed()
- startSpace);
if (ResponseCode.SUCCESS.equals(installBizClientResponse.getCode())) {
Expand Down Expand Up @@ -143,7 +145,17 @@ private void refreshBizInfoFromJar(Input input) throws IOException {
@Getter
@Setter
public static class Input extends ArkBizMeta {
private String bizUrl;
private String bizUrl;
/**
* can set --key=value, or just args
*/
private String[] args;

/**
* only used in multi-tenant jdk which support to set env for each Biz
* Don't use this in non-multi-tenant jdk.
*/
private Map<String, String> envs;
}

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
package com.alipay.sofa.koupleless.arklet.core.ops;

import java.util.List;
import java.util.Map;

import com.alipay.sofa.ark.api.ClientResponse;
import com.alipay.sofa.ark.spi.model.Biz;
import com.alipay.sofa.koupleless.arklet.core.ArkletComponent;
import com.alipay.sofa.koupleless.arklet.core.command.meta.bizops.ArkBizMeta;
import com.alipay.sofa.koupleless.arklet.core.common.model.BatchInstallRequest;
import com.alipay.sofa.koupleless.arklet.core.common.model.BatchInstallResponse;

Expand All @@ -37,7 +39,8 @@ public interface UnifiedOperationService extends ArkletComponent {
* @return response
* @throws Throwable error
*/
ClientResponse install(String bizUrl) throws Throwable;
ClientResponse install(String bizName, String bizVersion, String bizUrl, String[] args,
Map<String, String> envs) throws Throwable;

/**
* uninstall biz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@ public void destroy() {
}

@Override
public ClientResponse install(String bizUrl) throws Throwable {
public ClientResponse install(String bizName, String bizVersion, String bizUrl, String[] args,
Map<String, String> envs) throws Throwable {
BizOperation bizOperation = new BizOperation()
.setOperationType(BizOperation.OperationType.INSTALL);
bizOperation.setBizName(bizName);
bizOperation.setBizVersion(bizVersion);
bizOperation.putParameter(Constants.CONFIG_BIZ_URL, bizUrl);
return ArkClient.installOperation(bizOperation);
return ArkClient.installOperation(bizOperation, args, envs);
}

public ClientResponse safeBatchInstall(String bizUrl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public void testHandle_Success() throws Throwable {
Input input = new Input();
input.setBizUrl("testUrl");

when(handler.getOperationService().install(input.getBizUrl())).thenReturn(success);
when(
handler.getOperationService().install(input.getBizName(), input.getBizVersion(),
input.getBizUrl(), input.getArgs(), input.getEnvs())).thenReturn(success);

Output<InstallBizHandler.InstallBizClientResponse> result = handler.handle(input);

Expand All @@ -78,7 +80,9 @@ public void testHandle_Failure() throws Throwable {
Input input = new Input();
input.setBizUrl("testUrl");

when(handler.getOperationService().install(input.getBizUrl())).thenReturn(failed);
when(
handler.getOperationService().install(input.getBizName(), input.getBizVersion(),
input.getBizUrl(), input.getArgs(), input.getEnvs())).thenReturn(failed);

Output<InstallBizHandler.InstallBizClientResponse> result = handler.handle(input);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public void testDestroy() {
public void testInstallWithValidUrl() throws Throwable {
try (MockedStatic<ArkClient> arkClientMockedStatic = Mockito.mockStatic(ArkClient.class)) {
ClientResponse clientResponse = Mockito.mock(ClientResponse.class);
arkClientMockedStatic.when(() -> ArkClient.installOperation(Mockito.any(BizOperation.class))).thenReturn(clientResponse);
ClientResponse response = unifiedOperationService.install("http://example.com/biz.jar");
arkClientMockedStatic.verify(() -> ArkClient.installOperation(Mockito.any(BizOperation.class)));
arkClientMockedStatic.when(() -> ArkClient.installOperation(Mockito.any(BizOperation.class), Mockito.any(String[].class), Mockito.anyMap())).thenReturn(clientResponse);
ClientResponse response = unifiedOperationService.install("bizName", "bizVersion", "http://example.com/biz.jar", new String[]{}, new HashMap<>());
arkClientMockedStatic.verify(() -> ArkClient.installOperation(Mockito.any(BizOperation.class), Mockito.any(String[].class), Mockito.anyMap()));
Assert.assertEquals(clientResponse, response);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public void start(String[] strings) throws Throwable {

}

@Override
public void start(String[] strings, Map<String, String> map) throws Throwable {

}

@Override
public void stop() throws Throwable {

Expand Down

0 comments on commit ece024e

Please sign in to comment.