Wenjun Ruan
4 months ago
committed by
GitHub
23 changed files with 305 additions and 199 deletions
@ -0,0 +1,54 @@
|
||||
/* |
||||
* 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 org.apache.dolphinscheduler.dao.utils; |
||||
|
||||
public class EnvironmentUtils { |
||||
|
||||
private static final long EMPTY_ENVIRONMENT_CODE = -1L; |
||||
|
||||
/** |
||||
* Check if the environment code is empty (we should use null instead of -1, this is used to comply with the original code) |
||||
* |
||||
* @return true if the environment code is empty, false otherwise |
||||
*/ |
||||
public static boolean isEnvironmentCodeEmpty(Long environmentCode) { |
||||
return environmentCode == null || environmentCode <= 0; |
||||
} |
||||
|
||||
/** |
||||
* Get the empty environment code |
||||
*/ |
||||
public static Long getDefaultEnvironmentCode() { |
||||
return EMPTY_ENVIRONMENT_CODE; |
||||
} |
||||
|
||||
/** |
||||
* Get the environment code or the default environment code if the environment code is empty |
||||
*/ |
||||
public static Long getEnvironmentCodeOrDefault(Long environmentCode) { |
||||
return getEnvironmentCodeOrDefault(environmentCode, getDefaultEnvironmentCode()); |
||||
} |
||||
|
||||
/** |
||||
* Get the environment code or the default environment code if the environment code is empty |
||||
*/ |
||||
public static Long getEnvironmentCodeOrDefault(Long environmentCode, Long defaultEnvironmentCode) { |
||||
return isEnvironmentCodeEmpty(environmentCode) ? defaultEnvironmentCode : environmentCode; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,45 @@
|
||||
/* |
||||
* 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 org.apache.dolphinscheduler.dao.utils; |
||||
|
||||
import org.apache.commons.lang3.StringUtils; |
||||
|
||||
public class WorkerGroupUtils { |
||||
|
||||
private static final String DEFAULT_WORKER_GROUP = "default"; |
||||
|
||||
/** |
||||
* Check if the worker group is empty, if the worker group is default, it is considered empty |
||||
*/ |
||||
public static boolean isWorkerGroupEmpty(String workerGroup) { |
||||
return StringUtils.isEmpty(workerGroup) || getDefaultWorkerGroup().equals(workerGroup); |
||||
} |
||||
|
||||
public static String getWorkerGroupOrDefault(String workerGroup) { |
||||
return getWorkerGroupOrDefault(workerGroup, getDefaultWorkerGroup()); |
||||
} |
||||
|
||||
public static String getWorkerGroupOrDefault(String workerGroup, String defaultWorkerGroup) { |
||||
return isWorkerGroupEmpty(workerGroup) ? defaultWorkerGroup : workerGroup; |
||||
} |
||||
|
||||
public static String getDefaultWorkerGroup() { |
||||
return DEFAULT_WORKER_GROUP; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,72 @@
|
||||
/* |
||||
* 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 org.apache.dolphinscheduler.dao.utils; |
||||
|
||||
import static com.google.common.truth.Truth.assertThat; |
||||
|
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.params.ParameterizedTest; |
||||
import org.junit.jupiter.params.provider.CsvSource; |
||||
import org.junit.jupiter.params.provider.ValueSource; |
||||
|
||||
class EnvironmentUtilsTest { |
||||
|
||||
@ParameterizedTest |
||||
@ValueSource(longs = {0, -1}) |
||||
void testIsEnvironmentCodeEmpty_emptyEnvironmentCode(Long environmentCode) { |
||||
assertThat(EnvironmentUtils.isEnvironmentCodeEmpty(environmentCode)).isTrue(); |
||||
} |
||||
|
||||
@ParameterizedTest |
||||
@ValueSource(longs = {123}) |
||||
void testIsEnvironmentCodeEmpty_nonEmptyEnvironmentCode(Long environmentCode) { |
||||
assertThat(EnvironmentUtils.isEnvironmentCodeEmpty(environmentCode)).isFalse(); |
||||
} |
||||
|
||||
@Test |
||||
void testGetDefaultEnvironmentCode() { |
||||
assertThat(EnvironmentUtils.getDefaultEnvironmentCode()).isEqualTo(-1L); |
||||
} |
||||
|
||||
@ParameterizedTest |
||||
@ValueSource(longs = {0, -1}) |
||||
void testGetEnvironmentCodeOrDefault_emptyEnvironmentCode(Long environmentCode) { |
||||
assertThat(EnvironmentUtils.getEnvironmentCodeOrDefault(environmentCode)).isEqualTo(-1L); |
||||
} |
||||
|
||||
@ParameterizedTest |
||||
@ValueSource(longs = {123}) |
||||
void testGetEnvironmentCodeOrDefault_nonEmptyEnvironmentCode(Long environmentCode) { |
||||
assertThat(EnvironmentUtils.getEnvironmentCodeOrDefault(environmentCode)).isEqualTo(environmentCode); |
||||
} |
||||
|
||||
@ParameterizedTest |
||||
@CsvSource(value = {",123", "-1,123"}) |
||||
void testGetEnvironmentCodeOrDefault_withDefaultValue_emptyEnvironmentCode(Long environmentCode, |
||||
Long defaultValue) { |
||||
assertThat(EnvironmentUtils.getEnvironmentCodeOrDefault(environmentCode, defaultValue)).isEqualTo(defaultValue); |
||||
} |
||||
|
||||
@ParameterizedTest |
||||
@CsvSource(value = {"1,123"}) |
||||
void testGetEnvironmentCodeOrDefault_withDefaultValue_nonEmptyEnvironmentCode(Long environmentCode, |
||||
Long defaultValue) { |
||||
assertThat(EnvironmentUtils.getEnvironmentCodeOrDefault(environmentCode, defaultValue)) |
||||
.isEqualTo(environmentCode); |
||||
} |
||||
} |
@ -0,0 +1,70 @@
|
||||
/* |
||||
* 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 org.apache.dolphinscheduler.dao.utils; |
||||
|
||||
import static com.google.common.truth.Truth.assertThat; |
||||
|
||||
import org.junit.jupiter.api.Test; |
||||
import org.junit.jupiter.params.ParameterizedTest; |
||||
import org.junit.jupiter.params.provider.CsvSource; |
||||
import org.junit.jupiter.params.provider.ValueSource; |
||||
|
||||
class WorkerGroupUtilsTest { |
||||
|
||||
@ParameterizedTest |
||||
@ValueSource(strings = {"", "default"}) |
||||
void testIsWorkerGroupEmpty_emptyWorkerGroup(String workerGroup) { |
||||
assertThat(WorkerGroupUtils.isWorkerGroupEmpty(workerGroup)).isTrue(); |
||||
} |
||||
|
||||
@ParameterizedTest |
||||
@ValueSource(strings = {"123", "default1"}) |
||||
void testIsWorkerGroupEmpty_nonEmptyWorkerGroup(String workerGroup) { |
||||
assertThat(WorkerGroupUtils.isWorkerGroupEmpty(workerGroup)).isFalse(); |
||||
} |
||||
|
||||
@ParameterizedTest |
||||
@ValueSource(strings = {"", "default"}) |
||||
void testGetWorkerGroupOrDefault_emptyWorkerGroup(String workerGroup) { |
||||
assertThat(WorkerGroupUtils.getWorkerGroupOrDefault(workerGroup)) |
||||
.isEqualTo(WorkerGroupUtils.getDefaultWorkerGroup()); |
||||
} |
||||
|
||||
@ParameterizedTest |
||||
@ValueSource(strings = {"test"}) |
||||
void testGetWorkerGroupOrDefault_nonEmptyWorkerGroup(String workerGroup) { |
||||
assertThat(WorkerGroupUtils.getWorkerGroupOrDefault(workerGroup)).isEqualTo(workerGroup); |
||||
} |
||||
|
||||
@ParameterizedTest |
||||
@CsvSource(value = {",test", "default,test"}) |
||||
void testGetWorkerGroupOrDefault_withDefaultValue_emptyWorkerGroup(String workerGroup, String defaultValue) { |
||||
assertThat(WorkerGroupUtils.getWorkerGroupOrDefault(workerGroup, defaultValue)).isEqualTo(defaultValue); |
||||
} |
||||
|
||||
@ParameterizedTest |
||||
@CsvSource(value = {"test1,test"}) |
||||
void testGetWorkerGroupOrDefault_withDefaultValue_nonEmptyWorkerGroup(String workerGroup, String defaultValue) { |
||||
assertThat(WorkerGroupUtils.getWorkerGroupOrDefault(workerGroup)).isEqualTo(workerGroup); |
||||
} |
||||
|
||||
@Test |
||||
void getDefaultWorkerGroup() { |
||||
assertThat(WorkerGroupUtils.getDefaultWorkerGroup()).isEqualTo("default"); |
||||
} |
||||
} |
@ -1,57 +0,0 @@
|
||||
/* |
||||
* 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 org.apache.dolphinscheduler.server.master.dispatch.context; |
||||
|
||||
import static org.apache.dolphinscheduler.common.constants.Constants.DEFAULT_WORKER_GROUP; |
||||
|
||||
import org.apache.dolphinscheduler.dao.entity.TaskInstance; |
||||
import org.apache.dolphinscheduler.extract.base.utils.Host; |
||||
import org.apache.dolphinscheduler.server.master.dispatch.enums.ExecutorType; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Builder; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
|
||||
@Data |
||||
@Builder |
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
public class ExecutionContext { |
||||
|
||||
private Host host; |
||||
|
||||
private TaskInstance taskInstance; |
||||
|
||||
private ExecutorType executorType; |
||||
|
||||
/** |
||||
* worker group |
||||
*/ |
||||
private String workerGroup; |
||||
|
||||
public ExecutionContext(ExecutorType executorType, TaskInstance taskInstance) { |
||||
this(executorType, DEFAULT_WORKER_GROUP, taskInstance); |
||||
} |
||||
|
||||
public ExecutionContext(ExecutorType executorType, String workerGroup, TaskInstance taskInstance) { |
||||
this.executorType = executorType; |
||||
this.workerGroup = workerGroup; |
||||
this.taskInstance = taskInstance; |
||||
} |
||||
} |
Loading…
Reference in new issue