From d63ca19c4179058d9c13cc4c20a58fcffd493c5d Mon Sep 17 00:00:00 2001 From: mingmen Date: Mon, 4 Sep 2023 16:31:16 +0800 Subject: [PATCH] append doc --- arklet/README.md | 52 +++++++++++++++---- .../health/HealthAutoConfiguration.java | 25 +++++++-- .../endpoint/ArkHealthCodeEndpoint.java | 29 ++++++++--- .../health/endpoint/ArkHealthzEndpoint.java | 36 ++++++++++--- .../endpoint/model/EndpointResponse.java | 23 ++++++-- .../endpoint/model/EndpointResponseCode.java | 21 ++++++-- .../indicator/MasterBizHealthIndicator.java | 23 ++++++-- 7 files changed, 173 insertions(+), 36 deletions(-) diff --git a/arklet/README.md b/arklet/README.md index bfff4b2c2..c5ca50f55 100644 --- a/arklet/README.md +++ b/arklet/README.md @@ -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: @@ -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: diff --git a/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/HealthAutoConfiguration.java b/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/HealthAutoConfiguration.java index cc4e09edc..1fc02e4ef 100644 --- a/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/HealthAutoConfiguration.java +++ b/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/HealthAutoConfiguration.java @@ -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; @@ -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 includePath = exposure.getInclude(); includePath.add("*"); @@ -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; } diff --git a/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/endpoint/ArkHealthCodeEndpoint.java b/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/endpoint/ArkHealthCodeEndpoint.java index 8aab1ea39..fb7b0463f 100644 --- a/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/endpoint/ArkHealthCodeEndpoint.java +++ b/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/endpoint/ArkHealthCodeEndpoint.java @@ -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; @@ -9,7 +25,6 @@ import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import org.springframework.boot.actuate.endpoint.annotation.Selector; - /** * @author Lunarscave */ @@ -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 @@ -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) { diff --git a/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/endpoint/ArkHealthzEndpoint.java b/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/endpoint/ArkHealthzEndpoint.java index c05e50000..58069e7fc 100644 --- a/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/endpoint/ArkHealthzEndpoint.java +++ b/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/endpoint/ArkHealthzEndpoint.java @@ -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; @@ -23,8 +39,8 @@ public class ArkHealthzEndpoint { @ReadOperation public EndpointResponse> getHealth() { return ArkHealthzEndpoint.ofResponse(Health.createHealth() - .putAllHealthData(healthService.getHealth()) - .putAllHealthData(healthService.queryModuleInfo())); + .putAllHealthData(healthService.getHealth()) + .putAllHealthData(healthService.queryModuleInfo())); } @ReadOperation @@ -33,19 +49,25 @@ public EndpointResponse> getModuleInfo(@Selector String modu } @ReadOperation - public EndpointResponse> getModuleInfo(@Selector String moduleType, @Selector String name, @Selector String version) { - return ArkHealthzEndpoint.ofResponse(healthService.queryModuleInfo(moduleType, name, version)); + public EndpointResponse> getModuleInfo(@Selector String moduleType, + @Selector String name, + @Selector String version) { + return ArkHealthzEndpoint.ofResponse(healthService.queryModuleInfo(moduleType, name, + version)); } private static EndpointResponse> ofResponse(Health health) { Map healthData = health.getHealthData(); EndpointResponse> 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); } diff --git a/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/endpoint/model/EndpointResponse.java b/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/endpoint/model/EndpointResponse.java index 31e2cd823..f2f303015 100644 --- a/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/endpoint/model/EndpointResponse.java +++ b/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/endpoint/model/EndpointResponse.java @@ -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.model; /** @@ -5,10 +21,10 @@ */ public class EndpointResponse { - private boolean healthy; - private int code; + private boolean healthy; + private int code; private EndpointResponseCode codeType; - private T data; + private T data; private EndpointResponse() { } @@ -22,7 +38,6 @@ public static EndpointResponse ofSuccess(T data) { return endpointResponse; } - public static EndpointResponse ofFailed(EndpointResponseCode codeType, T data) { EndpointResponse endpointResponse = new EndpointResponse<>(); endpointResponse.healthy = false; diff --git a/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/endpoint/model/EndpointResponseCode.java b/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/endpoint/model/EndpointResponseCode.java index 75f6a84ca..501a302c0 100644 --- a/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/endpoint/model/EndpointResponseCode.java +++ b/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/endpoint/model/EndpointResponseCode.java @@ -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.model; /** @@ -5,10 +21,7 @@ */ 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; diff --git a/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/extension/indicator/MasterBizHealthIndicator.java b/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/extension/indicator/MasterBizHealthIndicator.java index 9d3ba9215..819b3fe48 100644 --- a/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/extension/indicator/MasterBizHealthIndicator.java +++ b/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/extension/indicator/MasterBizHealthIndicator.java @@ -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; @@ -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); @@ -25,7 +41,8 @@ public MasterBizHealthIndicator() { protected Map getHealthDetails() { AssertUtils.assertNotNull(applicationAvailability, "applicationAvailability must not null"); Map masterBizHealthDetails = new HashMap<>(1); - masterBizHealthDetails.put(MasterBizHealthMetrics.READINESS_STATE.getId(), applicationAvailability.getReadinessState()); + masterBizHealthDetails.put(MasterBizHealthMetrics.READINESS_STATE.getId(), + applicationAvailability.getReadinessState()); return masterBizHealthDetails; } @@ -43,7 +60,7 @@ enum MasterBizHealthMetrics { this.id = desc; } - public String getId(){ + public String getId() { return id; }; }