diff --git a/temporal-sdk/src/main/java/io/temporal/activity/ActivityMethod.java b/temporal-sdk/src/main/java/io/temporal/activity/ActivityMethod.java index 776e5f1449..8fa6aaef2d 100644 --- a/temporal-sdk/src/main/java/io/temporal/activity/ActivityMethod.java +++ b/temporal-sdk/src/main/java/io/temporal/activity/ActivityMethod.java @@ -40,6 +40,8 @@ * *
Be careful with names that contain special characters, as these names can be used as metric * tags. Systems like Prometheus ignore metrics which have tags with unsupported characters. + * + *
Name cannot start with __temporal_ as it is reserved for internal use.
*/
String name() default "";
}
diff --git a/temporal-sdk/src/main/java/io/temporal/common/metadata/POJOActivityImplMetadata.java b/temporal-sdk/src/main/java/io/temporal/common/metadata/POJOActivityImplMetadata.java
index 3878c612cf..d9f51f91ef 100644
--- a/temporal-sdk/src/main/java/io/temporal/common/metadata/POJOActivityImplMetadata.java
+++ b/temporal-sdk/src/main/java/io/temporal/common/metadata/POJOActivityImplMetadata.java
@@ -23,6 +23,7 @@
import com.google.common.collect.ImmutableList;
import io.temporal.activity.ActivityMethod;
import io.temporal.common.MethodRetry;
+import io.temporal.internal.common.InternalUtils;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
@@ -90,6 +91,7 @@ private POJOActivityImplMetadata(Class> implClass) {
activityInterfaces.add(interfaceMetadata);
List Be careful about names that contain special characters. These names can be used as metric
* tags. And systems like prometheus ignore metrics which have tags with unsupported characters.
+ *
+ * Name cannot start with __temporal as it is reserved for internal use. The name also cannot
+ * be __stack_trace or __enhanced_stack_trace as they are reserved for internal use.
*/
String name() default "";
diff --git a/temporal-sdk/src/main/java/io/temporal/workflow/SignalMethod.java b/temporal-sdk/src/main/java/io/temporal/workflow/SignalMethod.java
index b3839720af..57830c2ae9 100644
--- a/temporal-sdk/src/main/java/io/temporal/workflow/SignalMethod.java
+++ b/temporal-sdk/src/main/java/io/temporal/workflow/SignalMethod.java
@@ -57,6 +57,8 @@
*
* Be careful about names that contain special characters. These names can be used as metric
* tags. And systems like prometheus ignore metrics which have tags with unsupported characters.
+ *
+ * Name cannot start with __temporal_ as it is reserved for internal use.
*/
String name() default "";
diff --git a/temporal-sdk/src/main/java/io/temporal/workflow/UpdateMethod.java b/temporal-sdk/src/main/java/io/temporal/workflow/UpdateMethod.java
index 5a52be4e17..0e2d920d44 100644
--- a/temporal-sdk/src/main/java/io/temporal/workflow/UpdateMethod.java
+++ b/temporal-sdk/src/main/java/io/temporal/workflow/UpdateMethod.java
@@ -39,6 +39,8 @@
*
* Be careful about names that contain special characters. These names can be used as metric
* tags. And systems like prometheus ignore metrics which have tags with unsupported characters.
+ *
+ * Name cannot start with __temporal as it is reserved for internal use.
*/
String name() default "";
diff --git a/temporal-sdk/src/main/java/io/temporal/workflow/WorkflowMethod.java b/temporal-sdk/src/main/java/io/temporal/workflow/WorkflowMethod.java
index 1afee4830b..729f6919ca 100644
--- a/temporal-sdk/src/main/java/io/temporal/workflow/WorkflowMethod.java
+++ b/temporal-sdk/src/main/java/io/temporal/workflow/WorkflowMethod.java
@@ -33,6 +33,13 @@
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface WorkflowMethod {
- /** Name of the workflow type. Default is {short class name} */
+ /**
+ * Name of the workflow type. Default is {short class name}.
+ *
+ * Be careful with names that contain special characters, as these names can be used as metric
+ * tags. Systems like Prometheus ignore metrics which have tags with unsupported characters.
+ *
+ * Name cannot start with __temporal_ as it is reserved for internal use.
+ */
String name() default "";
}
diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRestrictedNameTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRestrictedNameTest.java
new file mode 100644
index 0000000000..4dc7c8edcd
--- /dev/null
+++ b/temporal-sdk/src/test/java/io/temporal/workflow/WorkflowRestrictedNameTest.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
+ *
+ * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Modifications copyright (C) 2017 Uber Technologies, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this material 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 io.temporal.workflow;
+
+import io.temporal.testing.internal.SDKTestWorkflowRule;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class WorkflowRestrictedNameTest {
+
+ @Rule
+ public SDKTestWorkflowRule testWorkflowRule =
+ SDKTestWorkflowRule.newBuilder().setDoNotStart(true).build();
+
+ @Test
+ public void testRegisteringRestrictedWorkflowMethod() {
+ IllegalArgumentException e =
+ Assert.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ testWorkflowRule
+ .getWorker()
+ .registerWorkflowImplementationTypes(WorkflowMethodWithOverrideNameImpl.class));
+ Assert.assertEquals(
+ "workflow name \"__temporal_workflow\" must not start with \"__temporal_\"",
+ e.getMessage());
+
+ e =
+ Assert.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ testWorkflowRule
+ .getWorker()
+ .registerWorkflowImplementationTypes(WorkflowMethodRestrictedImpl.class));
+ Assert.assertEquals(
+ "workflow name \"__temporal_workflow\" must not start with \"__temporal_\"",
+ e.getMessage());
+ }
+
+ @WorkflowInterface
+ public interface WorkflowMethodWithOverrideNameRestricted {
+ @WorkflowMethod(name = "__temporal_workflow")
+ void workflowMethod();
+ }
+
+ public static class WorkflowMethodWithOverrideNameImpl
+ implements WorkflowMethodWithOverrideNameRestricted {
+
+ @Override
+ public void workflowMethod() {}
+ }
+
+ @WorkflowInterface
+ public interface __temporal_workflow {
+ @WorkflowMethod
+ void workflowMethod();
+ }
+
+ public static class WorkflowMethodRestrictedImpl implements __temporal_workflow {
+ @Override
+ public void workflowMethod() {}
+ }
+}
diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRestrictedNameTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRestrictedNameTest.java
new file mode 100644
index 0000000000..b0c1eac434
--- /dev/null
+++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ActivityRestrictedNameTest.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
+ *
+ * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Modifications copyright (C) 2017 Uber Technologies, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this material 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 io.temporal.workflow.activityTests;
+
+import io.temporal.activity.*;
+import io.temporal.testing.internal.SDKTestWorkflowRule;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class ActivityRestrictedNameTest {
+
+ @Rule
+ public SDKTestWorkflowRule testWorkflowRule =
+ SDKTestWorkflowRule.newBuilder().setDoNotStart(true).build();
+
+ @Test
+ public void testRegisteringRestrictedActivity() {
+ IllegalArgumentException e =
+ Assert.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ testWorkflowRule
+ .getWorker()
+ .registerActivitiesImplementations(new ActivityWithRestrictedNamesImpl()));
+ Assert.assertEquals(
+ "Activity name \"__temporal_activity\" must not start with \"__temporal_\"",
+ e.getMessage());
+
+ e =
+ Assert.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ testWorkflowRule
+ .getWorker()
+ .registerActivitiesImplementations(
+ new ActivityWithRestrictedOverrideNameImpl()));
+ Assert.assertEquals(
+ "Activity name \"__temporal_activity\" must not start with \"__temporal_\"",
+ e.getMessage());
+ }
+
+ @ActivityInterface
+ public interface ActivityWithRestrictedOverrideName {
+
+ @ActivityMethod(name = "__temporal_activity")
+ String temporalActivity(String workflowId);
+ }
+
+ public static class ActivityWithRestrictedOverrideNameImpl
+ implements ActivityWithRestrictedOverrideName {
+ @Override
+ public String temporalActivity(String workflowId) {
+ return null;
+ }
+ }
+
+ @ActivityInterface
+ public interface ActivityWithRestrictedNames {
+ String __temporal_activity(String workflowId);
+ }
+
+ public static class ActivityWithRestrictedNamesImpl implements ActivityWithRestrictedNames {
+ @Override
+ public String __temporal_activity(String workflowId) {
+ return null;
+ }
+ }
+}
diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/queryTests/QueryRestrictedNameTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/queryTests/QueryRestrictedNameTest.java
new file mode 100644
index 0000000000..dbac704283
--- /dev/null
+++ b/temporal-sdk/src/test/java/io/temporal/workflow/queryTests/QueryRestrictedNameTest.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
+ *
+ * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Modifications copyright (C) 2017 Uber Technologies, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this material 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 io.temporal.workflow.queryTests;
+
+import io.temporal.testing.internal.SDKTestWorkflowRule;
+import io.temporal.workflow.QueryMethod;
+import io.temporal.workflow.WorkflowInterface;
+import io.temporal.workflow.WorkflowMethod;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class QueryRestrictedNameTest {
+
+ @Rule
+ public SDKTestWorkflowRule testWorkflowRule =
+ SDKTestWorkflowRule.newBuilder().setDoNotStart(true).build();
+
+ @Test
+ public void testRegisteringRestrictedQueryMethod() {
+ IllegalArgumentException e =
+ Assert.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ testWorkflowRule
+ .getWorker()
+ .registerWorkflowImplementationTypes(
+ QueryMethodWithOverrideNameRestrictedImpl.class));
+ Assert.assertEquals(
+ "query name \"__temporal_query\" must not start with \"__temporal_\"", e.getMessage());
+
+ e =
+ Assert.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ testWorkflowRule
+ .getWorker()
+ .registerWorkflowImplementationTypes(QueryMethodNameRestrictedImpl.class));
+ Assert.assertEquals(
+ "query name \"__temporal_query\" must not start with \"__temporal_\"", e.getMessage());
+ }
+
+ @WorkflowInterface
+ public interface QueryMethodWithOverrideNameRestricted {
+ @WorkflowMethod
+ void workflowMethod();
+
+ @QueryMethod(name = "__temporal_query")
+ int queryMethod();
+ }
+
+ public static class QueryMethodWithOverrideNameRestrictedImpl
+ implements QueryMethodWithOverrideNameRestricted {
+
+ @Override
+ public void workflowMethod() {}
+
+ @Override
+ public int queryMethod() {
+ return 0;
+ }
+ }
+
+ @WorkflowInterface
+ public interface QueryMethodNameRestricted {
+ @WorkflowMethod
+ void workflowMethod();
+
+ @QueryMethod()
+ int __temporal_query();
+ }
+
+ public static class QueryMethodNameRestrictedImpl implements QueryMethodNameRestricted {
+ @Override
+ public void workflowMethod() {}
+
+ @Override
+ public int __temporal_query() {
+ return 0;
+ }
+ }
+}
diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalRestrictedNameTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalRestrictedNameTest.java
new file mode 100644
index 0000000000..fd8396a1dc
--- /dev/null
+++ b/temporal-sdk/src/test/java/io/temporal/workflow/signalTests/SignalRestrictedNameTest.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
+ *
+ * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Modifications copyright (C) 2017 Uber Technologies, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this material 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 io.temporal.workflow.signalTests;
+
+import io.temporal.testing.internal.SDKTestWorkflowRule;
+import io.temporal.workflow.SignalMethod;
+import io.temporal.workflow.WorkflowInterface;
+import io.temporal.workflow.WorkflowMethod;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class SignalRestrictedNameTest {
+
+ @Rule
+ public SDKTestWorkflowRule testWorkflowRule =
+ SDKTestWorkflowRule.newBuilder().setDoNotStart(true).build();
+
+ @Test
+ public void testRegisteringRestrictedSignalMethod() {
+ IllegalArgumentException e =
+ Assert.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ testWorkflowRule
+ .getWorker()
+ .registerWorkflowImplementationTypes(
+ SignalMethodWithOverrideNameRestrictedImpl.class));
+ Assert.assertEquals(
+ "signal name \"__temporal_signal\" must not start with \"__temporal_\"", e.getMessage());
+
+ e =
+ Assert.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ testWorkflowRule
+ .getWorker()
+ .registerWorkflowImplementationTypes(SignalMethodNameRestrictedImpl.class));
+ Assert.assertEquals(
+ "signal name \"__temporal_signal\" must not start with \"__temporal_\"", e.getMessage());
+ }
+
+ @WorkflowInterface
+ public interface SignalMethodWithOverrideNameRestricted {
+ @WorkflowMethod
+ void workflowMethod();
+
+ @SignalMethod(name = "__temporal_signal")
+ void signalMethod();
+ }
+
+ public static class SignalMethodWithOverrideNameRestrictedImpl
+ implements SignalMethodWithOverrideNameRestricted {
+
+ @Override
+ public void workflowMethod() {}
+
+ @Override
+ public void signalMethod() {}
+ }
+
+ @WorkflowInterface
+ public interface SignalMethodNameRestricted {
+ @WorkflowMethod
+ void workflowMethod();
+
+ @SignalMethod()
+ void __temporal_signal();
+ }
+
+ public static class SignalMethodNameRestrictedImpl implements SignalMethodNameRestricted {
+ @Override
+ public void workflowMethod() {}
+
+ @Override
+ public void __temporal_signal() {}
+ }
+}
diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/updateTest/UpdateRestrictedNameTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/updateTest/UpdateRestrictedNameTest.java
new file mode 100644
index 0000000000..dc4e291e32
--- /dev/null
+++ b/temporal-sdk/src/test/java/io/temporal/workflow/updateTest/UpdateRestrictedNameTest.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
+ *
+ * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Modifications copyright (C) 2017 Uber Technologies, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this material 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 io.temporal.workflow.updateTest;
+
+import io.temporal.testing.internal.SDKTestWorkflowRule;
+import io.temporal.workflow.UpdateMethod;
+import io.temporal.workflow.WorkflowInterface;
+import io.temporal.workflow.WorkflowMethod;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class UpdateRestrictedNameTest {
+
+ @Rule
+ public SDKTestWorkflowRule testWorkflowRule =
+ SDKTestWorkflowRule.newBuilder().setDoNotStart(true).build();
+
+ @Test
+ public void testRegisteringRestrictedUpdateMethod() {
+ IllegalArgumentException e =
+ Assert.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ testWorkflowRule
+ .getWorker()
+ .registerWorkflowImplementationTypes(
+ UpdateMethodWithOverrideNameRestrictedImpl.class));
+ Assert.assertEquals(
+ "update name \"__temporal_update\" must not start with \"__temporal_\"", e.getMessage());
+
+ e =
+ Assert.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ testWorkflowRule
+ .getWorker()
+ .registerWorkflowImplementationTypes(UpdateMethodNameRestrictedImpl.class));
+ Assert.assertEquals(
+ "update name \"__temporal_update\" must not start with \"__temporal_\"", e.getMessage());
+ }
+
+ @WorkflowInterface
+ public interface UpdateMethodWithOverrideNameRestricted {
+ @WorkflowMethod
+ void workflowMethod();
+
+ @UpdateMethod(name = "__temporal_update")
+ void updateMethod();
+ }
+
+ public static class UpdateMethodWithOverrideNameRestrictedImpl
+ implements UpdateMethodWithOverrideNameRestricted {
+
+ @Override
+ public void workflowMethod() {}
+
+ @Override
+ public void updateMethod() {}
+ }
+
+ @WorkflowInterface
+ public interface UpdateMethodNameRestricted {
+ @WorkflowMethod
+ void workflowMethod();
+
+ @UpdateMethod()
+ void __temporal_update();
+ }
+
+ public static class UpdateMethodNameRestrictedImpl implements UpdateMethodNameRestricted {
+ @Override
+ public void workflowMethod() {}
+
+ @Override
+ public void __temporal_update() {}
+ }
+}