|
| 1 | +/* |
| 2 | + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved |
| 3 | + * |
| 4 | + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 5 | + * |
| 6 | + * Modifications copyright (C) 2017 Uber Technologies, Inc. |
| 7 | + * |
| 8 | + * Licensed under the Apache License, Version 2.0 (the "License"). You may not |
| 9 | + * use this file except in compliance with the License. A copy of the License is |
| 10 | + * located at |
| 11 | + * |
| 12 | + * http://aws.amazon.com/apache2.0 |
| 13 | + * |
| 14 | + * or in the "license" file accompanying this file. This file is distributed on |
| 15 | + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 16 | + * express or implied. See the License for the specific language governing |
| 17 | + * permissions and limitations under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package io.temporal.samples.springboot.actuator; |
| 21 | + |
| 22 | +import io.temporal.common.metadata.*; |
| 23 | +import io.temporal.spring.boot.autoconfigure.template.WorkersTemplate; |
| 24 | +import java.lang.reflect.Method; |
| 25 | +import java.util.Map; |
| 26 | +import java.util.stream.Collectors; |
| 27 | +import org.springframework.beans.factory.annotation.Autowired; |
| 28 | +import org.springframework.beans.factory.annotation.Qualifier; |
| 29 | +import org.springframework.boot.actuate.endpoint.annotation.Endpoint; |
| 30 | +import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; |
| 31 | +import org.springframework.stereotype.Component; |
| 32 | + |
| 33 | +@Component |
| 34 | +@Endpoint(id = "temporalworkerinfo") |
| 35 | +public class WorkerActuatorEndpoint { |
| 36 | + @Autowired |
| 37 | + @Qualifier("temporalWorkersTemplate") |
| 38 | + private WorkersTemplate workersTemplate; |
| 39 | + |
| 40 | + @ReadOperation |
| 41 | + public String workerInfo() { |
| 42 | + StringBuilder sb = new StringBuilder(); |
| 43 | + Map<String, WorkersTemplate.RegisteredInfo> registeredInfo = |
| 44 | + workersTemplate.getRegisteredInfo(); |
| 45 | + sb.append("Worker Info:"); |
| 46 | + registeredInfo.forEach( |
| 47 | + (taskQueue, info) -> { |
| 48 | + sb.append("\n\n\tTask Queue: ").append(taskQueue); |
| 49 | + info.getRegisteredWorkflowInfo() |
| 50 | + .forEach( |
| 51 | + (workflowInfo) -> { |
| 52 | + sb.append("\n\t\t Workflow Interface: ").append(workflowInfo.getClassName()); |
| 53 | + POJOWorkflowImplMetadata metadata = workflowInfo.getMetadata(); |
| 54 | + sb.append("\n\t\t\t Workflow Methods: "); |
| 55 | + sb.append( |
| 56 | + metadata.getWorkflowMethods().stream() |
| 57 | + .map(POJOWorkflowMethodMetadata::getWorkflowMethod) |
| 58 | + .map(Method::getName) |
| 59 | + .collect(Collectors.joining(", "))); |
| 60 | + sb.append("\n\t\t\t Query Methods: "); |
| 61 | + sb.append( |
| 62 | + metadata.getQueryMethods().stream() |
| 63 | + .map(POJOWorkflowMethodMetadata::getWorkflowMethod) |
| 64 | + .map(Method::getName) |
| 65 | + .collect(Collectors.joining(", "))); |
| 66 | + sb.append("\n\t\t\t Signal Methods: "); |
| 67 | + sb.append( |
| 68 | + metadata.getSignalMethods().stream() |
| 69 | + .map(POJOWorkflowMethodMetadata::getWorkflowMethod) |
| 70 | + .map(Method::getName) |
| 71 | + .collect(Collectors.joining(", "))); |
| 72 | + sb.append("\n\t\t\t Update Methods: "); |
| 73 | + sb.append( |
| 74 | + metadata.getUpdateMethods().stream() |
| 75 | + .map(POJOWorkflowMethodMetadata::getWorkflowMethod) |
| 76 | + .map(Method::getName) |
| 77 | + .collect(Collectors.joining(","))); |
| 78 | + sb.append("\n\t\t\t Update Validator Methods: "); |
| 79 | + sb.append( |
| 80 | + metadata.getUpdateValidatorMethods().stream() |
| 81 | + .map(POJOWorkflowMethodMetadata::getWorkflowMethod) |
| 82 | + .map(Method::getName) |
| 83 | + .collect(Collectors.joining(", "))); |
| 84 | + }); |
| 85 | + info.getRegisteredActivityInfo() |
| 86 | + .forEach( |
| 87 | + (activityInfo) -> { |
| 88 | + sb.append("\n\t\t Activity Impl: ").append(activityInfo.getClassName()); |
| 89 | + POJOActivityImplMetadata metadata = activityInfo.getMetadata(); |
| 90 | + sb.append("\n\t\t\t Activity Interfaces: "); |
| 91 | + sb.append( |
| 92 | + metadata.getActivityInterfaces().stream() |
| 93 | + .map(POJOActivityInterfaceMetadata::getInterfaceClass) |
| 94 | + .map(Class::getName) |
| 95 | + .collect(Collectors.joining(","))); |
| 96 | + sb.append("\n\t\t\t Activity Methods: "); |
| 97 | + sb.append( |
| 98 | + metadata.getActivityMethods().stream() |
| 99 | + .map(POJOActivityMethodMetadata::getMethod) |
| 100 | + .map(Method::getName) |
| 101 | + .collect(Collectors.joining(", "))); |
| 102 | + }); |
| 103 | + }); |
| 104 | + |
| 105 | + return sb.toString(); |
| 106 | + } |
| 107 | +} |
0 commit comments