Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
append doc
Browse files Browse the repository at this point in the history
  • Loading branch information
TomorJM committed Sep 4, 2023
1 parent ac66b50 commit d63ca19
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 36 deletions.
52 changes: 43 additions & 9 deletions arklet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,46 @@ The http protocol is enabled and the default port is 1238
{
"bizName": "test",
"bizVersion": "1.0.0",
// local path should start with file://, alse support remote url which can be downloaded
"bizUrl": "file:///Users/jaimezhang/workspace/github/sofa-ark-dynamic-guides/dynamic-provider/target/dynamic-provider-1.0.0-ark-biz.jar"
}
```
- output sample:

- output sample(success):
```json
{
"code":"SUCCESS",
"data":[
{
"bizName":"dynamic-provider",
"bizVersion":"1.0.0",
...
}
]
"data":{
"bizInfos":[
{
"bizName":"dynamic-provider",
"bizState":"ACTIVATED",
"bizVersion":"1.0.0",
"declaredMode":true,
"identity":"dynamic-provider:1.0.0",
"mainClass":"io.sofastack.dynamic.provider.ProviderApplication",
"priority":100,
"webContextPath":"provider"
}
],
"code":"SUCCESS",
"message":"Install Biz: dynamic-provider:1.0.0 success, cost: 1092 ms, started at: 16:07:47,769"
}
}
```

- output sample(failed):
```json
{
"code":"FAILED",
"data":{
"code":"REPEAT_BIZ",
"message":"Biz: dynamic-provider:1.0.0 has been installed or registered."
}
}
```


## Uninstall a biz
- URL: 127.0.0.1:1238/uninstallBiz
- input sample:
Expand All @@ -94,13 +117,24 @@ The http protocol is enabled and the default port is 1238
"bizVersion":"1.0.0"
}
```
- output sample:
- output sample(success):
```json
{
"code":"SUCCESS"
}
```

- output sample(failed):
```json
{
"code":"FAILED",
"data":{
"code":"NOT_FOUND_BIZ",
"message":"Uninstall biz: test:1.0.0 not found."
}
}
```

## Switch a biz
- URL: 127.0.0.1:1238/switchBiz
- input sample:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* 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 com.alipay.sofa.serverless.arklet.springboot.starter.health;

import com.alipay.sofa.serverless.arklet.core.ArkletComponentRegistry;
Expand Down Expand Up @@ -28,7 +44,8 @@ public class HealthAutoConfiguration implements ApplicationContextAware {

@Bean
public void initEndpoint() {
WebEndpointProperties webEndpointProperties = this.context.getBean(WebEndpointProperties.class);
WebEndpointProperties webEndpointProperties = this.context
.getBean(WebEndpointProperties.class);
WebEndpointProperties.Exposure exposure = webEndpointProperties.getExposure();
Set<String> includePath = exposure.getInclude();
includePath.add("*");
Expand All @@ -52,8 +69,10 @@ public ArkHealthCodeEndpoint arkHealthCodeEndpoint() {
@DependsOn("componentRegistry")
public MasterBizHealthIndicator masterBizHealthIndicator() {
MasterBizHealthIndicator masterBizHealthIndicator = new MasterBizHealthIndicator();
masterBizHealthIndicator.setApplicationAvailability(context.getBean(ApplicationAvailability.class));
ArkletComponentRegistry.getHealthServiceInstance().registerIndicator(masterBizHealthIndicator);
masterBizHealthIndicator.setApplicationAvailability(context
.getBean(ApplicationAvailability.class));
ArkletComponentRegistry.getHealthServiceInstance().registerIndicator(
masterBizHealthIndicator);
return masterBizHealthIndicator;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* 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 com.alipay.sofa.serverless.arklet.springboot.starter.health.endpoint;

import com.alipay.sofa.serverless.arklet.core.ArkletComponentRegistry;
Expand All @@ -9,7 +25,6 @@
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.Selector;


/**
* @author Lunarscave
*/
Expand All @@ -19,10 +34,10 @@ public class ArkHealthCodeEndpoint {
private final HealthService healthService = ArkletComponentRegistry.getHealthServiceInstance();

@ReadOperation
public int healthCode(){
public int healthCode() {
return ArkHealthCodeEndpoint.ofCode(Health.createHealth()
.putAllHealthData(healthService.getHealth())
.putAllHealthData(healthService.queryModuleInfo()));
.putAllHealthData(healthService.getHealth())
.putAllHealthData(healthService.queryModuleInfo()));
}

@ReadOperation
Expand All @@ -31,8 +46,10 @@ public int getModuleInfoHealthCode(@Selector String moduleType) {
}

@ReadOperation
public int getModuleInfoHealthCode(@Selector String moduleType, @Selector String name, @Selector String version) {
return ArkHealthCodeEndpoint.ofCode(healthService.queryModuleInfo(moduleType, name, version));
public int getModuleInfoHealthCode(@Selector String moduleType, @Selector String name,
@Selector String version) {
return ArkHealthCodeEndpoint.ofCode(healthService
.queryModuleInfo(moduleType, name, version));
}

public static int ofCode(Health health) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* 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 com.alipay.sofa.serverless.arklet.springboot.starter.health.endpoint;

import com.alipay.sofa.serverless.arklet.core.ArkletComponentRegistry;
Expand All @@ -23,8 +39,8 @@ public class ArkHealthzEndpoint {
@ReadOperation
public EndpointResponse<Map<String, Object>> getHealth() {
return ArkHealthzEndpoint.ofResponse(Health.createHealth()
.putAllHealthData(healthService.getHealth())
.putAllHealthData(healthService.queryModuleInfo()));
.putAllHealthData(healthService.getHealth())
.putAllHealthData(healthService.queryModuleInfo()));
}

@ReadOperation
Expand All @@ -33,19 +49,25 @@ public EndpointResponse<Map<String, Object>> getModuleInfo(@Selector String modu
}

@ReadOperation
public EndpointResponse<Map<String, Object>> getModuleInfo(@Selector String moduleType, @Selector String name, @Selector String version) {
return ArkHealthzEndpoint.ofResponse(healthService.queryModuleInfo(moduleType, name, version));
public EndpointResponse<Map<String, Object>> getModuleInfo(@Selector String moduleType,
@Selector String name,
@Selector String version) {
return ArkHealthzEndpoint.ofResponse(healthService.queryModuleInfo(moduleType, name,
version));
}

private static EndpointResponse<Map<String, Object>> ofResponse(Health health) {
Map<String, Object> healthData = health.getHealthData();
EndpointResponse<Map<String, Object>> endpointResponse;
if (Health.containsError(health, Constants.HEALTH_ENDPOINT_ERROR)) {
endpointResponse = EndpointResponse.ofFailed(EndpointResponseCode.ENDPOINT_NOT_FOUND, healthData);
endpointResponse = EndpointResponse.ofFailed(EndpointResponseCode.ENDPOINT_NOT_FOUND,
healthData);
} else if (Health.containsError(health, Constants.HEALTH_ERROR)) {
endpointResponse = EndpointResponse.ofFailed(EndpointResponseCode.ENDPOINT_PROCESS_INTERNAL_ERROR, healthData);
endpointResponse = EndpointResponse.ofFailed(
EndpointResponseCode.ENDPOINT_PROCESS_INTERNAL_ERROR, healthData);
} else if (Health.containsUnhealthy(health, Constants.READINESS_HEALTHY)) {
endpointResponse = EndpointResponse.ofFailed(EndpointResponseCode.UNHEALTHY, healthData);
endpointResponse = EndpointResponse
.ofFailed(EndpointResponseCode.UNHEALTHY, healthData);
} else {
endpointResponse = EndpointResponse.ofSuccess(healthData);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
/*
* 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 com.alipay.sofa.serverless.arklet.springboot.starter.health.endpoint.model;

/**
* @author Lunarscave
*/
public class EndpointResponse<T> {

private boolean healthy;
private int code;
private boolean healthy;
private int code;
private EndpointResponseCode codeType;
private T data;
private T data;

private EndpointResponse() {
}
Expand All @@ -22,7 +38,6 @@ public static <T> EndpointResponse<T> ofSuccess(T data) {
return endpointResponse;
}


public static <T> EndpointResponse<T> ofFailed(EndpointResponseCode codeType, T data) {
EndpointResponse<T> endpointResponse = new EndpointResponse<>();
endpointResponse.healthy = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
/*
* 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 com.alipay.sofa.serverless.arklet.springboot.starter.health.endpoint.model;

/**
* @author Lunarscave
*/
public enum EndpointResponseCode {

HEALTHY(200),
UNHEALTHY(400),
ENDPOINT_NOT_FOUND(404),
ENDPOINT_PROCESS_INTERNAL_ERROR(500);
HEALTHY(200), UNHEALTHY(400), ENDPOINT_NOT_FOUND(404), ENDPOINT_PROCESS_INTERNAL_ERROR(500);

private final int code;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* 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 com.alipay.sofa.serverless.arklet.springboot.starter.health.extension.indicator;

import com.alipay.sofa.serverless.arklet.core.health.indicator.ArkletBaseIndicator;
Expand All @@ -15,7 +31,7 @@ public class MasterBizHealthIndicator extends ArkletBaseIndicator {

private ApplicationAvailability applicationAvailability;

private final static String MASTER_BIZ_HEALTH_INDICATOR_ID = Constants.MASTER_BIZ_HEALTH;
private final static String MASTER_BIZ_HEALTH_INDICATOR_ID = Constants.MASTER_BIZ_HEALTH;

public MasterBizHealthIndicator() {
super(MASTER_BIZ_HEALTH_INDICATOR_ID);
Expand All @@ -25,7 +41,8 @@ public MasterBizHealthIndicator() {
protected Map<String, Object> getHealthDetails() {
AssertUtils.assertNotNull(applicationAvailability, "applicationAvailability must not null");
Map<String, Object> masterBizHealthDetails = new HashMap<>(1);
masterBizHealthDetails.put(MasterBizHealthMetrics.READINESS_STATE.getId(), applicationAvailability.getReadinessState());
masterBizHealthDetails.put(MasterBizHealthMetrics.READINESS_STATE.getId(),
applicationAvailability.getReadinessState());
return masterBizHealthDetails;
}

Expand All @@ -43,7 +60,7 @@ enum MasterBizHealthMetrics {
this.id = desc;
}

public String getId(){
public String getId() {
return id;
};
}
Expand Down

0 comments on commit d63ca19

Please sign in to comment.