diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/FederationApplicationInputValidator.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/FederationApplicationInputValidator.java new file mode 100644 index 0000000..169c429 --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/FederationApplicationInputValidator.java @@ -0,0 +1,173 @@ +/** + * 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.hadoop.yarn.server.federation.store; + +import org.apache.hadoop.yarn.api.records.ApplicationId; +import org.apache.hadoop.yarn.server.federation.store.records.AddApplicationHomeSubClusterRequest; +import org.apache.hadoop.yarn.server.federation.store.records.ApplicationHomeSubCluster; +import org.apache.hadoop.yarn.server.federation.store.records.DeleteApplicationHomeSubClusterRequest; +import org.apache.hadoop.yarn.server.federation.store.records.GetApplicationHomeSubClusterRequest; +import org.apache.hadoop.yarn.server.federation.store.records.UpdateApplicationHomeSubClusterRequest; + +/** + * Utility class to validate the inputs to + * {@link FederationApplicationHomeSubClusterStore}, allows a fail fast + * mechanism for invalid user inputs. + * + */ +public final class FederationApplicationInputValidator { + + private FederationApplicationInputValidator() { + } + + /** + * Quick validation on the input to check some obvious fail conditions (fail + * fast). Check if the provided {@link AddApplicationHomeSubClusterRequest} + * for adding a new application is valid or not. + * + * @param request the {@link AddApplicationHomeSubClusterRequest} to validate + * against + * @throws FederationStateStoreInvalidInputException if the request is invalid + */ + public static void validateAddApplicationHomeSubClusterRequest( + AddApplicationHomeSubClusterRequest request) + throws FederationStateStoreInvalidInputException { + if (request == null) { + throw new FederationStateStoreInvalidInputException( + "Missing AddApplicationHomeSubCluster Request." + + " Please try again by specifying an" + + " AddApplicationHomeSubCluster information."); + } + + // validate ApplicationHomeSubCluster info + checkApplicationHomeSubCluster(request.getApplicationHomeSubCluster()); + } + + /** + * Quick validation on the input to check some obvious fail conditions (fail + * fast). Check if the provided {@link UpdateApplicationHomeSubClusterRequest} + * for updating an application is valid or not. + * + * @param request the {@link UpdateApplicationHomeSubClusterRequest} to + * validate against + * @throws FederationStateStoreInvalidInputException if the request is invalid + */ + public static void validateUpdateApplicationHomeSubClusterRequest( + UpdateApplicationHomeSubClusterRequest request) + throws FederationStateStoreInvalidInputException { + if (request == null) { + throw new FederationStateStoreInvalidInputException( + "Missing UpdateApplicationHomeSubCluster Request." + + " Please try again by specifying an" + + " ApplicationHomeSubCluster information."); + } + + // validate ApplicationHomeSubCluster info + checkApplicationHomeSubCluster(request.getApplicationHomeSubCluster()); + } + + /** + * Quick validation on the input to check some obvious fail conditions (fail + * fast). Check if the provided {@link GetApplicationHomeSubClusterRequest} + * for querying application's information is valid or not. + * + * @param request the {@link GetApplicationHomeSubClusterRequest} to validate + * against + * @throws FederationStateStoreInvalidInputException if the request is invalid + */ + public static void validateGetApplicationHomeSubClusterRequest( + GetApplicationHomeSubClusterRequest request) + throws FederationStateStoreInvalidInputException { + if (request == null) { + throw new FederationStateStoreInvalidInputException( + "Missing GetApplicationHomeSubCluster Request." + + " Please try again by specifying an" + + " Application Id information."); + } + + // validate application Id + checkApplicationId(request.getApplicationId()); + } + + /** + * Quick validation on the input to check some obvious fail conditions (fail + * fast). Check if the provided {@link DeleteApplicationHomeSubClusterRequest} + * for deleting an application is valid or not. + * + * @param request the {@link DeleteApplicationHomeSubClusterRequest} to + * validate against + * @throws FederationStateStoreInvalidInputException if the request is invalid + */ + public static void validateDeleteApplicationHomeSubClusterRequest( + DeleteApplicationHomeSubClusterRequest request) + throws FederationStateStoreInvalidInputException { + if (request == null) { + throw new FederationStateStoreInvalidInputException( + "Missing DeleteApplicationHomeSubCluster Request." + + " Please try again by specifying an" + + " ApplicationHomeSubCluster information."); + } + + // validate application Id + checkApplicationId(request.getApplicationId()); + } + + /** + * Validate if the ApplicationHomeSubCluster info are present or not. + * + * @param applicationHomeSubCluster the information of the application to be + * verified + * @throws FederationStateStoreInvalidInputException if the SubCluster Info + * are invalid + */ + private static void checkApplicationHomeSubCluster( + ApplicationHomeSubCluster applicationHomeSubCluster) + + throws FederationStateStoreInvalidInputException { + if (applicationHomeSubCluster == null) { + throw new FederationStateStoreInvalidInputException( + "Missing ApplicationHomeSubCluster Info." + + " Please try again by specifying an" + + " ApplicationHomeSubCluster information."); + } + // validate application Id + checkApplicationId(applicationHomeSubCluster.getApplicationId()); + + // validate subcluster Id + FederationMembershipInputValidator + .checkSubClusterId(applicationHomeSubCluster.getHomeSubCluster()); + + } + + /** + * Validate if the application id is present or not. + * + * @param appId the id of the application to be verified + * @throws FederationStateStoreInvalidInputException if the application Id is + * invalid + */ + private static void checkApplicationId(ApplicationId appId) + throws FederationStateStoreInvalidInputException { + if (appId == null) { + throw new FederationStateStoreInvalidInputException( + "Missing Application Id." + + " Please try again by specifying an Application Id."); + } + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/FederationMembershipInputValidator.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/FederationMembershipInputValidator.java new file mode 100644 index 0000000..0c4fc42 --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/FederationMembershipInputValidator.java @@ -0,0 +1,301 @@ +/** + * 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.hadoop.yarn.server.federation.store; + +import java.net.URI; + +import org.apache.hadoop.yarn.server.federation.store.records.GetSubClusterInfoRequest; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterDeregisterRequest; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterHeartbeatRequest; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterInfo; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterRegisterRequest; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterState; + +/** + * Utility class to validate the inputs to + * {@link FederationMembershipStateStore}, allows a fail fast mechanism for + * invalid user inputs. + * + */ +public final class FederationMembershipInputValidator { + + private FederationMembershipInputValidator() { + } + + /** + * Quick validation on the input to check some obvious fail conditions (fail + * fast). Check if the provided {@link SubClusterRegisterRequest} for + * registration a new subcluster is valid or not. + * + * @param request the {@link SubClusterRegisterRequest} to validate against + * @throws FederationStateStoreInvalidInputException if the request is invalid + */ + public static void validateSubClusterRegisterRequest( + SubClusterRegisterRequest request) + throws FederationStateStoreInvalidInputException { + + // check if the request is present + if (request == null) { + throw new FederationStateStoreInvalidInputException( + "Missing SubClusterRegister Request." + + " Please try again by specifying a" + + " SubCluster Register Information."); + } + + // validate subcluster info + checkSubClusterInfo(request.getSubClusterInfo()); + } + + /** + * Quick validation on the input to check some obvious fail conditions (fail + * fast). Check if the provided {@link SubClusterDeregisterRequest} for + * deregistration a subcluster is valid or not. + * + * @param request the {@link SubClusterDeregisterRequest} to validate against + * @throws FederationStateStoreInvalidInputException if the request is invalid + */ + public static void validateSubClusterDeregisterRequest( + SubClusterDeregisterRequest request) + throws FederationStateStoreInvalidInputException { + + // check if the request is present + if (request == null) { + throw new FederationStateStoreInvalidInputException( + "Missing SubClusterDeregister Request." + + " Please try again by specifying a" + + " SubCluster Deregister Information."); + } + + // validate subcluster id + checkSubClusterId(request.getSubClusterId()); + // validate subcluster state + checkSubClusterState(request.getState()); + if (!request.getState().isFinal()) { + throw new FederationStateStoreInvalidInputException( + "Invalid non-final state: " + request.getState()); + } + } + + /** + * Quick validation on the input to check some obvious fail conditions (fail + * fast). Check if the provided {@link SubClusterHeartbeatRequest} for + * heartbeating a subcluster is valid or not. + * + * @param request the {@link SubClusterHeartbeatRequest} to validate against + * @throws FederationStateStoreInvalidInputException if the request is invalid + */ + public static void validateSubClusterHeartbeatRequest( + SubClusterHeartbeatRequest request) + throws FederationStateStoreInvalidInputException { + + // check if the request is present + if (request == null) { + throw new FederationStateStoreInvalidInputException( + "Missing SubClusterHeartbeat Request." + + " Please try again by specifying a" + + " SubCluster Heartbeat Information."); + } + + // validate subcluster id + checkSubClusterId(request.getSubClusterId()); + // validate last heartbeat timestamp + checkTimestamp(request.getLastHeartBeat()); + // validate subcluster capability + checkCapability(request.getCapability()); + // validate subcluster state + checkSubClusterState(request.getState()); + + } + + /** + * Quick validation on the input to check some obvious fail conditions (fail + * fast). Check if the provided {@link GetSubClusterInfoRequest} for querying + * subcluster's information is valid or not. + * + * @param request the {@link GetSubClusterInfoRequest} to validate against + * @throws FederationStateStoreInvalidInputException if the request is invalid + */ + public static void validateGetSubClusterInfoRequest( + GetSubClusterInfoRequest request) + throws FederationStateStoreInvalidInputException { + + // check if the request is present + if (request == null) { + throw new FederationStateStoreInvalidInputException( + "Missing GetSubClusterInfo Request." + + " Please try again by specifying a" + + " Get SubCluster information."); + } + + // validate subcluster id + checkSubClusterId(request.getSubClusterId()); + } + + /** + * Validate if the SubCluster Info are present or not. + * + * @param subClusterInfo the information of the subcluster to be verified + * @throws FederationStateStoreInvalidInputException if the SubCluster Info + * are invalid + */ + private static void checkSubClusterInfo(SubClusterInfo subClusterInfo) + throws FederationStateStoreInvalidInputException { + if (subClusterInfo == null) { + throw new FederationStateStoreInvalidInputException( + "Missing Subcluster Information." + + " Please try again by specifying Subcluster Information."); + } + + // validate subcluster id + checkSubClusterId(subClusterInfo.getSubClusterId()); + + // validate AMRM Service address + checkAddress(subClusterInfo.getAMRMServiceAddress()); + // validate ClientRM Service address + checkAddress(subClusterInfo.getClientRMServiceAddress()); + // validate RMClient Service address + checkAddress(subClusterInfo.getRMAdminServiceAddress()); + // validate RMWeb Service address + checkAddress(subClusterInfo.getRMWebServiceAddress()); + + // validate last heartbeat timestamp + checkTimestamp(subClusterInfo.getLastHeartBeat()); + // validate last start timestamp + checkTimestamp(subClusterInfo.getLastStartTime()); + + // validate subcluster state + checkSubClusterState(subClusterInfo.getState()); + + // validate subcluster capability + checkCapability(subClusterInfo.getCapability()); + } + + /** + * Validate if the timestamp is positive or not. + * + * @param timestamp the timestamp to be verified + * @throws FederationStateStoreInvalidInputException if the timestamp is + * invalid + */ + private static void checkTimestamp(long timestamp) + throws FederationStateStoreInvalidInputException { + if (timestamp < 0) { + throw new FederationStateStoreInvalidInputException( + "Invalid timestamp information." + + " Please try again by specifying valid Timestamp Information."); + } + } + + /** + * Validate if the Capability is present or not. + * + * @param capability the capability of the subcluster to be verified + * @throws FederationStateStoreInvalidInputException if the capability is + * invalid + */ + private static void checkCapability(String capability) + throws FederationStateStoreInvalidInputException { + if (capability == null || capability.isEmpty()) { + throw new FederationStateStoreInvalidInputException( + "Invalid capability information." + + " Please try again by specifying valid" + + " Capability Information."); + } + } + + /** + * Validate if the SubCluster Id is present or not. + * + * @param subClusterId the identifier of the subcluster to be verified + * @throws FederationStateStoreInvalidInputException if the SubCluster Id is + * invalid + */ + protected static void checkSubClusterId(SubClusterId subClusterId) + throws FederationStateStoreInvalidInputException { + // check if cluster id is present + if (subClusterId == null) { + throw new FederationStateStoreInvalidInputException( + "Missing Subcluster Id information." + + " Please try again by specifying Subcluster Id information."); + } + // check if cluster id is valid + if (subClusterId.getId().isEmpty()) { + throw new FederationStateStoreInvalidInputException( + "Invalid Subcluster Id information." + + " Please try again by specifying valid Subcluster Id."); + } + } + + /** + * Validate if the SubCluster Address is a valid URL or not. + * + * @param address the endpoint of the subcluster to be verified + * @throws FederationStateStoreInvalidInputException if the address is invalid + */ + private static void checkAddress(String address) + throws FederationStateStoreInvalidInputException { + // Ensure url is not null + if (address == null || address.isEmpty()) { + throw new FederationStateStoreInvalidInputException( + "Missing subclusterEndpoint information." + + " Please try again by specifying Subcluster" + + " Endpoint information."); + } + // Validate url is well formed + boolean hasScheme = address.contains("://"); + URI uri = null; + try { + uri = hasScheme ? URI.create(address) + : URI.create("dummyscheme://" + address); + } catch (IllegalArgumentException e) { + throw new FederationStateStoreInvalidInputException( + "The provided Subcluster Endpoint does not contain a" + + " valid host:port authority: " + address); + } + String host = uri.getHost(); + int port = uri.getPort(); + String path = uri.getPath(); + if ((host == null) || (port < 0) + || (!hasScheme && path != null && !path.isEmpty())) { + throw new FederationStateStoreInvalidInputException( + "The provided Subcluster Endpoint does not contain a" + + " valid host:port authority: " + address); + } + } + + /** + * Validate if the SubCluster State is present or not. + * + * @param state the state of the subcluster to be verified + * @throws FederationStateStoreInvalidInputException if the SubCluster State + * is invalid + */ + private static void checkSubClusterState(SubClusterState state) + throws FederationStateStoreInvalidInputException { + // check sub-cluster state is not empty + if (state == null) { + throw new FederationStateStoreInvalidInputException( + "Missing Subcluster State information." + + " Please try again by specifying Subcluster" + + " State information."); + } + } + +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/FederationPolicyInputValidator.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/FederationPolicyInputValidator.java new file mode 100644 index 0000000..dfd8df9 --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/FederationPolicyInputValidator.java @@ -0,0 +1,134 @@ +/** + * 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.hadoop.yarn.server.federation.store; + +import org.apache.hadoop.yarn.server.federation.store.records.GetSubClusterPolicyConfigurationRequest; +import org.apache.hadoop.yarn.server.federation.store.records.SetSubClusterPolicyConfigurationRequest; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterPolicyConfiguration; + +/** + * Utility class to validate the inputs to {@link FederationPolicyStore}, allows + * a fail fast mechanism for invalid user inputs. + * + */ +public final class FederationPolicyInputValidator { + + private FederationPolicyInputValidator() { + } + + /** + * Quick validation on the input to check some obvious fail conditions (fail + * fast). Check if the provided + * {@link GetSubClusterPolicyConfigurationRequest} for querying policy's + * information is valid or not. + * + * @param request the {@link GetSubClusterPolicyConfigurationRequest} to + * validate against + * @throws FederationStateStoreInvalidInputException if the request is invalid + */ + public static void validateGetSubClusterPolicyConfigurationRequest( + GetSubClusterPolicyConfigurationRequest request) + throws FederationStateStoreInvalidInputException { + if (request == null) { + throw new FederationStateStoreInvalidInputException( + "Missing GetSubClusterPolicyConfiguration Request." + + " Please try again by specifying an queue information."); + } + + // validate queue id + checkQueue(request.getQueue()); + } + + /** + * Quick validation on the input to check some obvious fail conditions (fail + * fast). Check if the provided + * {@link SetSubClusterPolicyConfigurationRequest} for adding a new policy is + * valid or not. + * + * @param request the {@link SetSubClusterPolicyConfigurationRequest} to + * validate against + * @throws FederationStateStoreInvalidInputException if the request is invalid + */ + public static void validateSetSubClusterPolicyConfigurationRequest( + SetSubClusterPolicyConfigurationRequest request) + throws FederationStateStoreInvalidInputException { + if (request == null) { + throw new FederationStateStoreInvalidInputException( + "Missing SetSubClusterPolicyConfiguration Request." + + " Please try again by specifying an" + + " policy insertion information."); + } + + // validate subcluster policy configuration + checkSubClusterPolicyConfiguration(request.getPolicyConfiguration()); + } + + /** + * Validate if the SubClusterPolicyConfiguration is valid or not. + * + * @param policyConfiguration the policy information to be verified + * @throws FederationStateStoreInvalidInputException if the policy information + * are invalid + */ + private static void checkSubClusterPolicyConfiguration( + SubClusterPolicyConfiguration policyConfiguration) + throws FederationStateStoreInvalidInputException { + if (policyConfiguration == null) { + throw new FederationStateStoreInvalidInputException( + "Missing SubClusterPolicyConfiguration." + + " Please try again by specifying a Queue Id."); + } + + // validate queue id + checkQueue(policyConfiguration.getQueue()); + // validate policy type + checkType(policyConfiguration.getType()); + + } + + /** + * Validate if the queue id is a valid or not. + * + * @param queue the queue id of the policy to be verified + * @throws FederationStateStoreInvalidInputException if the queue id is + * invalid + */ + private static void checkQueue(String queue) + throws FederationStateStoreInvalidInputException { + if (queue == null || queue.isEmpty()) { + throw new FederationStateStoreInvalidInputException( + "Missing Queue Id. Please try again by specifying a Queue Id."); + } + } + + /** + * Validate if the policy type is a valid or not. + * + * @param type the type of the policy to be verified + * @throws FederationStateStoreInvalidInputException if the policy is invalid + */ + private static void checkType(String type) + throws FederationStateStoreInvalidInputException { + if (type == null || type.isEmpty()) { + throw new FederationStateStoreInvalidInputException("Missing Policy Type." + + " Please try again by specifying a Policy Type."); + } + } + +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/FederationStateStoreInvalidInputException.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/FederationStateStoreInvalidInputException.java new file mode 100644 index 0000000..6c20747 --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/federation/store/FederationStateStoreInvalidInputException.java @@ -0,0 +1,48 @@ +/** + * 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.hadoop.yarn.server.federation.store; + +import org.apache.hadoop.yarn.exceptions.YarnException; + +/** + * Exception thrown by the {@link FederationMembershipInputValidator}, + * {@link FederationApplicationInputValidator}, + * {@link FederationPolicyInputValidator} if the input is invalid. + * + */ +public class FederationStateStoreInvalidInputException extends YarnException { + + /** + * IDE auto-generated. + */ + private static final long serialVersionUID = -7352144682711430801L; + + public FederationStateStoreInvalidInputException(Throwable cause) { + super(cause); + } + + public FederationStateStoreInvalidInputException(String message) { + super(message); + } + + public FederationStateStoreInvalidInputException(String message, + Throwable cause) { + super(message, cause); + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/store/TestFederationStateStoreInputValidator.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/store/TestFederationStateStoreInputValidator.java new file mode 100644 index 0000000..5d172fe --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/test/java/org/apache/hadoop/yarn/server/federation/store/TestFederationStateStoreInputValidator.java @@ -0,0 +1,1287 @@ +/** + * 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.hadoop.yarn.server.federation.store; + +import java.nio.ByteBuffer; + +import org.apache.hadoop.yarn.api.records.ApplicationId; +import org.apache.hadoop.yarn.server.federation.store.records.AddApplicationHomeSubClusterRequest; +import org.apache.hadoop.yarn.server.federation.store.records.ApplicationHomeSubCluster; +import org.apache.hadoop.yarn.server.federation.store.records.DeleteApplicationHomeSubClusterRequest; +import org.apache.hadoop.yarn.server.federation.store.records.GetApplicationHomeSubClusterRequest; +import org.apache.hadoop.yarn.server.federation.store.records.GetSubClusterInfoRequest; +import org.apache.hadoop.yarn.server.federation.store.records.GetSubClusterPolicyConfigurationRequest; +import org.apache.hadoop.yarn.server.federation.store.records.SetSubClusterPolicyConfigurationRequest; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterDeregisterRequest; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterHeartbeatRequest; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterInfo; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterPolicyConfiguration; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterRegisterRequest; +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterState; +import org.apache.hadoop.yarn.server.federation.store.records.UpdateApplicationHomeSubClusterRequest; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Unit tests for FederationApplicationInputValidator, + * FederationMembershipInputValidator, and FederationPolicyInputValidator. + */ +public class TestFederationStateStoreInputValidator { + + private static final Logger LOG = + LoggerFactory.getLogger(TestFederationStateStoreInputValidator.class); + + private static SubClusterId subClusterIdCorrect; + private static String amRMServiceAddressCorrect; + private static String clientRMServiceAddressCorrect; + private static String rmAdminServiceAddressCorrect; + private static String rmWebServiceAddressCorrect; + private static int lastHeartBeatCorrect; + private static SubClusterState stateNew; + private static SubClusterState stateLost; + private static ApplicationId appIdCorrect; + private static int lastStartTimeCorrect; + private static String capabilityCorrect; + private static String queueCorrect; + private static String typeCorrect; + private static ByteBuffer params; + + private static SubClusterId subClusterIdInvalid; + private static SubClusterId subClusterIdNull; + + private static int lastHeartBeatNegative; + private static int lastStartTimeNegative; + + private static SubClusterState stateNull; + private static ApplicationId appIdNull; + + private static String capabilityNull; + private static String capabilityEmpty; + + private static String addressNull; + private static String addressEmpty; + private static String addressWrong; + private static String addressWrongPort; + + private static String queueEmpty; + private static String queueNull; + + private static String typeEmpty; + private static String typeNull; + + @BeforeClass + public static void setUp() { + subClusterIdCorrect = SubClusterId.newInstance("abc"); + amRMServiceAddressCorrect = "localhost:8032"; + clientRMServiceAddressCorrect = "localhost:8034"; + rmAdminServiceAddressCorrect = "localhost:8031"; + rmWebServiceAddressCorrect = "localhost:8088"; + lastHeartBeatCorrect = 1000; + stateNew = SubClusterState.SC_NEW; + stateLost = SubClusterState.SC_LOST; + lastStartTimeCorrect = 1000; + capabilityCorrect = "Memory VCores"; + appIdCorrect = ApplicationId.newInstance(lastStartTimeCorrect, 1); + queueCorrect = "default"; + typeCorrect = "random"; + params = ByteBuffer.allocate(10); + params.put((byte) 0xFF); + + subClusterIdInvalid = SubClusterId.newInstance(""); + subClusterIdNull = null; + + lastHeartBeatNegative = -10; + lastStartTimeNegative = -10; + + stateNull = null; + appIdNull = null; + + capabilityNull = null; + capabilityEmpty = ""; + + addressNull = null; + addressEmpty = ""; + addressWrong = "AddressWrong"; + addressWrongPort = "Address:WrongPort"; + + queueEmpty = ""; + queueNull = null; + + typeEmpty = ""; + typeNull = null; + } + + @Test + public void testValidateSubClusterRegisterRequest() { + + // Execution with valid inputs + + SubClusterInfo subClusterInfo = SubClusterInfo.newInstance( + subClusterIdCorrect, amRMServiceAddressCorrect, + clientRMServiceAddressCorrect, rmAdminServiceAddressCorrect, + rmWebServiceAddressCorrect, lastHeartBeatCorrect, stateNew, + lastStartTimeCorrect, capabilityCorrect); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + } catch (FederationStateStoreInvalidInputException e) { + Assert.fail(e.getMessage()); + } + + // Execution with null request + + try { + SubClusterRegisterRequest request = null; + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Missing SubClusterRegister Request.")); + } + + // Execution with null SubClusterInfo + + subClusterInfo = null; + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Missing Subcluster Information.")); + } + + // Execution with Invalid SubClusterId + + subClusterInfo = SubClusterInfo.newInstance(subClusterIdInvalid, + amRMServiceAddressCorrect, clientRMServiceAddressCorrect, + rmAdminServiceAddressCorrect, rmWebServiceAddressCorrect, + lastHeartBeatCorrect, stateNew, lastStartTimeCorrect, capabilityNull); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Invalid Subcluster Id information.")); + } + + // Execution with Null SubClusterId + + subClusterInfo = + SubClusterInfo.newInstance(subClusterIdNull, amRMServiceAddressCorrect, + clientRMServiceAddressCorrect, rmAdminServiceAddressCorrect, + rmWebServiceAddressCorrect, lastHeartBeatCorrect, stateNew, + lastStartTimeCorrect, capabilityCorrect); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Missing Subcluster Id information.")); + } + + // Execution with Null State + + subClusterInfo = SubClusterInfo.newInstance(subClusterIdCorrect, + amRMServiceAddressCorrect, clientRMServiceAddressCorrect, + rmAdminServiceAddressCorrect, rmWebServiceAddressCorrect, + lastHeartBeatCorrect, stateNull, lastStartTimeCorrect, + capabilityCorrect); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Missing Subcluster State information.")); + } + + // Execution with Null Capability + + subClusterInfo = SubClusterInfo.newInstance(subClusterIdCorrect, + amRMServiceAddressCorrect, clientRMServiceAddressCorrect, + rmAdminServiceAddressCorrect, rmWebServiceAddressCorrect, + lastHeartBeatCorrect, stateNew, lastStartTimeCorrect, capabilityNull); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Invalid capability information.")); + } + + // Execution with Empty Capability + + subClusterInfo = SubClusterInfo.newInstance(subClusterIdCorrect, + amRMServiceAddressCorrect, clientRMServiceAddressCorrect, + rmAdminServiceAddressCorrect, rmWebServiceAddressCorrect, + lastHeartBeatCorrect, stateNew, lastStartTimeCorrect, capabilityEmpty); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Invalid capability information.")); + } + } + + @Test + public void testValidateSubClusterRegisterRequestTimestamp() { + + // Execution with Negative Last Heartbeat + + SubClusterInfo subClusterInfo = SubClusterInfo.newInstance( + subClusterIdCorrect, amRMServiceAddressCorrect, + clientRMServiceAddressCorrect, rmAdminServiceAddressCorrect, + rmWebServiceAddressCorrect, lastHeartBeatNegative, stateNew, + lastStartTimeCorrect, capabilityCorrect); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Invalid timestamp information.")); + } + + // Execution with Negative Last StartTime + + subClusterInfo = SubClusterInfo.newInstance(subClusterIdCorrect, + amRMServiceAddressCorrect, clientRMServiceAddressCorrect, + rmAdminServiceAddressCorrect, rmWebServiceAddressCorrect, + lastHeartBeatCorrect, stateNew, lastStartTimeNegative, + capabilityCorrect); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Invalid timestamp information.")); + } + } + + @Test + public void testValidateSubClusterRegisterRequestAddress() { + // Execution with Null Address for amRMServiceAddress + + SubClusterInfo subClusterInfo = + SubClusterInfo.newInstance(subClusterIdCorrect, addressNull, + clientRMServiceAddressCorrect, rmAdminServiceAddressCorrect, + rmWebServiceAddressCorrect, lastHeartBeatCorrect, stateNew, + lastStartTimeCorrect, capabilityCorrect); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Missing subclusterEndpoint information.")); + } + + // Execution with Empty Address for amRMServiceAddress + + subClusterInfo = + SubClusterInfo.newInstance(subClusterIdCorrect, addressEmpty, + clientRMServiceAddressCorrect, rmAdminServiceAddressCorrect, + rmWebServiceAddressCorrect, lastHeartBeatCorrect, stateNew, + lastStartTimeCorrect, capabilityCorrect); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Missing subclusterEndpoint information.")); + } + + // Execution with Null Address for clientRMServiceAddress + + subClusterInfo = SubClusterInfo.newInstance(subClusterIdCorrect, + amRMServiceAddressCorrect, addressNull, rmAdminServiceAddressCorrect, + rmWebServiceAddressCorrect, lastHeartBeatCorrect, stateNew, + lastStartTimeCorrect, capabilityCorrect); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Missing subclusterEndpoint information.")); + } + + // Execution with Empty Address for clientRMServiceAddress + + subClusterInfo = SubClusterInfo.newInstance(subClusterIdCorrect, + amRMServiceAddressCorrect, addressEmpty, rmAdminServiceAddressCorrect, + rmWebServiceAddressCorrect, lastHeartBeatCorrect, stateNew, + lastStartTimeCorrect, capabilityCorrect); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Missing subclusterEndpoint information.")); + } + + // Execution with Null Address for rmAdminServiceAddress + + subClusterInfo = SubClusterInfo.newInstance(subClusterIdCorrect, + amRMServiceAddressCorrect, clientRMServiceAddressCorrect, addressNull, + rmWebServiceAddressCorrect, lastHeartBeatCorrect, stateNew, + lastStartTimeCorrect, capabilityCorrect); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Missing subclusterEndpoint information.")); + } + + // Execution with Empty Address for rmAdminServiceAddress + + subClusterInfo = SubClusterInfo.newInstance(subClusterIdCorrect, + amRMServiceAddressCorrect, clientRMServiceAddressCorrect, addressEmpty, + rmWebServiceAddressCorrect, lastHeartBeatCorrect, stateNew, + lastStartTimeCorrect, capabilityCorrect); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Missing subclusterEndpoint information.")); + } + + // Execution with Null Address for rmWebServiceAddress + + subClusterInfo = SubClusterInfo.newInstance(subClusterIdCorrect, + amRMServiceAddressCorrect, clientRMServiceAddressCorrect, + rmAdminServiceAddressCorrect, addressNull, lastHeartBeatCorrect, + stateNew, lastStartTimeCorrect, capabilityCorrect); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Missing subclusterEndpoint information.")); + } + + // Execution with Empty Address for rmWebServiceAddress + + subClusterInfo = SubClusterInfo.newInstance(subClusterIdCorrect, + amRMServiceAddressCorrect, clientRMServiceAddressCorrect, + rmAdminServiceAddressCorrect, addressEmpty, lastHeartBeatCorrect, + stateNew, lastStartTimeCorrect, capabilityCorrect); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Missing subclusterEndpoint information.")); + } + } + + @Test + public void testValidateSubClusterRegisterRequestAddressInvalid() { + + // Address is not in host:port format for amRMService + + SubClusterInfo subClusterInfo = + SubClusterInfo.newInstance(subClusterIdCorrect, addressWrong, + clientRMServiceAddressCorrect, rmAdminServiceAddressCorrect, + rmWebServiceAddressCorrect, lastHeartBeatCorrect, stateNull, + lastStartTimeCorrect, capabilityCorrect); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue(e.getMessage().contains("valid host:port authority:")); + } + + // Address is not in host:port format for clientRMService + + subClusterInfo = SubClusterInfo.newInstance(subClusterIdCorrect, + amRMServiceAddressCorrect, addressWrong, rmAdminServiceAddressCorrect, + rmWebServiceAddressCorrect, lastHeartBeatCorrect, stateNull, + lastStartTimeCorrect, capabilityCorrect); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue(e.getMessage().contains("valid host:port authority:")); + } + + // Address is not in host:port format for rmAdminService + + subClusterInfo = SubClusterInfo.newInstance(subClusterIdCorrect, + amRMServiceAddressCorrect, clientRMServiceAddressCorrect, addressWrong, + rmWebServiceAddressCorrect, lastHeartBeatCorrect, stateNull, + lastStartTimeCorrect, capabilityCorrect); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue(e.getMessage().contains("valid host:port authority:")); + } + + // Address is not in host:port format for rmWebService + + subClusterInfo = SubClusterInfo.newInstance(subClusterIdCorrect, + amRMServiceAddressCorrect, clientRMServiceAddressCorrect, + rmAdminServiceAddressCorrect, addressWrong, lastHeartBeatCorrect, + stateNull, lastStartTimeCorrect, capabilityCorrect); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue(e.getMessage().contains("valid host:port authority:")); + } + + // Port is not an integer for amRMService + + subClusterInfo = + SubClusterInfo.newInstance(subClusterIdCorrect, addressWrongPort, + clientRMServiceAddressCorrect, rmAdminServiceAddressCorrect, + rmWebServiceAddressCorrect, lastHeartBeatCorrect, stateNull, + lastStartTimeCorrect, capabilityCorrect); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue(e.getMessage().contains("valid host:port authority:")); + } + + // Port is not an integer for clientRMService + + subClusterInfo = SubClusterInfo.newInstance(subClusterIdCorrect, + amRMServiceAddressCorrect, addressWrongPort, + rmAdminServiceAddressCorrect, rmWebServiceAddressCorrect, + lastHeartBeatCorrect, stateNull, lastStartTimeCorrect, + capabilityCorrect); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue(e.getMessage().contains("valid host:port authority:")); + } + + // Port is not an integer for rmAdminService + + subClusterInfo = SubClusterInfo.newInstance(subClusterIdCorrect, + amRMServiceAddressCorrect, clientRMServiceAddressCorrect, + addressWrongPort, rmWebServiceAddressCorrect, lastHeartBeatCorrect, + stateNull, lastStartTimeCorrect, capabilityCorrect); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue(e.getMessage().contains("valid host:port authority:")); + } + + // Port is not an integer for rmWebService + + subClusterInfo = SubClusterInfo.newInstance(subClusterIdCorrect, + amRMServiceAddressCorrect, clientRMServiceAddressCorrect, + rmAdminServiceAddressCorrect, addressWrongPort, lastHeartBeatCorrect, + stateNull, lastStartTimeCorrect, capabilityCorrect); + try { + SubClusterRegisterRequest request = + SubClusterRegisterRequest.newInstance(subClusterInfo); + FederationMembershipInputValidator + .validateSubClusterRegisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue(e.getMessage().contains("valid host:port authority:")); + } + + } + + @Test + public void testValidateSubClusterDeregisterRequest() { + + // Execution with valid inputs + + try { + SubClusterDeregisterRequest request = SubClusterDeregisterRequest + .newInstance(subClusterIdCorrect, stateLost); + FederationMembershipInputValidator + .validateSubClusterDeregisterRequest(request); + } catch (FederationStateStoreInvalidInputException e) { + Assert.fail(e.getMessage()); + } + + // Execution with null request + + try { + SubClusterDeregisterRequest request = null; + FederationMembershipInputValidator + .validateSubClusterDeregisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Missing SubClusterDeregister Request.")); + } + + // Execution with invalid SubClusterId + + try { + SubClusterDeregisterRequest request = SubClusterDeregisterRequest + .newInstance(subClusterIdInvalid, stateLost); + FederationMembershipInputValidator + .validateSubClusterDeregisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Invalid Subcluster Id information.")); + } + + // Execution with null SubClusterId + + try { + SubClusterDeregisterRequest request = + SubClusterDeregisterRequest.newInstance(subClusterIdNull, stateLost); + FederationMembershipInputValidator + .validateSubClusterDeregisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Missing Subcluster Id information.")); + } + + // Execution with invalid SubClusterState + + try { + SubClusterDeregisterRequest request = SubClusterDeregisterRequest + .newInstance(subClusterIdCorrect, stateNew); + FederationMembershipInputValidator + .validateSubClusterDeregisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue(e.getMessage().startsWith("Invalid non-final state: ")); + } + + // Execution with null SubClusterState + + try { + SubClusterDeregisterRequest request = SubClusterDeregisterRequest + .newInstance(subClusterIdCorrect, stateNull); + FederationMembershipInputValidator + .validateSubClusterDeregisterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Missing Subcluster State information.")); + } + } + + @Test + public void testSubClusterHeartbeatRequestCorrect() { + + // Execution with valid inputs + + try { + SubClusterHeartbeatRequest request = + SubClusterHeartbeatRequest.newInstance(subClusterIdCorrect, + lastHeartBeatCorrect, stateLost, capabilityCorrect); + FederationMembershipInputValidator + .validateSubClusterHeartbeatRequest(request); + } catch (FederationStateStoreInvalidInputException e) { + Assert.fail(e.getMessage()); + } + + // Execution with null request + + try { + SubClusterHeartbeatRequest request = null; + FederationMembershipInputValidator + .validateSubClusterHeartbeatRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Missing SubClusterHeartbeat Request.")); + } + + // Execution with invalid SubClusterId + + try { + SubClusterHeartbeatRequest request = + SubClusterHeartbeatRequest.newInstance(subClusterIdInvalid, + lastHeartBeatCorrect, stateLost, capabilityCorrect); + FederationMembershipInputValidator + .validateSubClusterHeartbeatRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Invalid Subcluster Id information.")); + } + + // Execution with null SubClusterId + + try { + SubClusterHeartbeatRequest request = + SubClusterHeartbeatRequest.newInstance(subClusterIdNull, + lastHeartBeatCorrect, stateLost, capabilityCorrect); + FederationMembershipInputValidator + .validateSubClusterHeartbeatRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Missing Subcluster Id information.")); + } + + // Execution with null SubClusterState + + try { + SubClusterHeartbeatRequest request = + SubClusterHeartbeatRequest.newInstance(subClusterIdCorrect, + lastHeartBeatCorrect, stateNull, capabilityCorrect); + FederationMembershipInputValidator + .validateSubClusterHeartbeatRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Missing Subcluster State information.")); + } + + // Execution with negative Last Heartbeat + + try { + SubClusterHeartbeatRequest request = + SubClusterHeartbeatRequest.newInstance(subClusterIdCorrect, + lastHeartBeatNegative, stateLost, capabilityCorrect); + FederationMembershipInputValidator + .validateSubClusterHeartbeatRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Invalid timestamp information.")); + } + + // Execution with null Capability + + try { + SubClusterHeartbeatRequest request = + SubClusterHeartbeatRequest.newInstance(subClusterIdCorrect, + lastHeartBeatCorrect, stateLost, capabilityNull); + FederationMembershipInputValidator + .validateSubClusterHeartbeatRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Invalid capability information.")); + } + + // Execution with empty Capability + + try { + SubClusterHeartbeatRequest request = + SubClusterHeartbeatRequest.newInstance(subClusterIdCorrect, + lastHeartBeatCorrect, stateLost, capabilityEmpty); + FederationMembershipInputValidator + .validateSubClusterHeartbeatRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Invalid capability information.")); + } + } + + @Test + public void testGetSubClusterInfoRequestCorrect() { + + // Execution with valid inputs + + try { + GetSubClusterInfoRequest request = + GetSubClusterInfoRequest.newInstance(subClusterIdCorrect); + FederationMembershipInputValidator + .validateGetSubClusterInfoRequest(request); + } catch (FederationStateStoreInvalidInputException e) { + Assert.fail(e.getMessage()); + } + + // Execution with null request + + try { + GetSubClusterInfoRequest request = null; + FederationMembershipInputValidator + .validateGetSubClusterInfoRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Missing GetSubClusterInfo Request.")); + } + + // Execution with invalid SubClusterId + + try { + GetSubClusterInfoRequest request = + GetSubClusterInfoRequest.newInstance(subClusterIdInvalid); + FederationMembershipInputValidator + .validateGetSubClusterInfoRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Invalid Subcluster Id information.")); + } + + // Execution with null SubClusterId + + try { + GetSubClusterInfoRequest request = + GetSubClusterInfoRequest.newInstance(subClusterIdNull); + FederationMembershipInputValidator + .validateGetSubClusterInfoRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Missing Subcluster Id information.")); + } + } + + @Test + public void testAddApplicationHomeSubClusterRequestCorrect() { + + // Execution with valid inputs + + ApplicationHomeSubCluster applicationHomeSubCluster = + ApplicationHomeSubCluster.newInstance(appIdCorrect, + subClusterIdCorrect); + try { + AddApplicationHomeSubClusterRequest request = + AddApplicationHomeSubClusterRequest + .newInstance(applicationHomeSubCluster); + FederationApplicationInputValidator + .validateAddApplicationHomeSubClusterRequest(request); + } catch (FederationStateStoreInvalidInputException e) { + Assert.fail(e.getMessage()); + } + + // Execution with null request + + try { + AddApplicationHomeSubClusterRequest request = null; + FederationApplicationInputValidator + .validateAddApplicationHomeSubClusterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + Assert.assertTrue(e.getMessage() + .startsWith("Missing AddApplicationHomeSubCluster Request.")); + } + + // Execution with null ApplicationHomeSubCluster + + applicationHomeSubCluster = null; + try { + AddApplicationHomeSubClusterRequest request = + AddApplicationHomeSubClusterRequest + .newInstance(applicationHomeSubCluster); + FederationApplicationInputValidator + .validateAddApplicationHomeSubClusterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + Assert.assertTrue( + e.getMessage().startsWith("Missing ApplicationHomeSubCluster Info.")); + } + + // Execution with invalid SubClusterId + + applicationHomeSubCluster = ApplicationHomeSubCluster + .newInstance(appIdCorrect, subClusterIdInvalid); + try { + AddApplicationHomeSubClusterRequest request = + AddApplicationHomeSubClusterRequest + .newInstance(applicationHomeSubCluster); + FederationApplicationInputValidator + .validateAddApplicationHomeSubClusterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Invalid Subcluster Id information.")); + } + + // Execution with null SubClusterId + + applicationHomeSubCluster = + ApplicationHomeSubCluster.newInstance(appIdCorrect, subClusterIdNull); + try { + AddApplicationHomeSubClusterRequest request = + AddApplicationHomeSubClusterRequest + .newInstance(applicationHomeSubCluster); + FederationApplicationInputValidator + .validateAddApplicationHomeSubClusterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Missing Subcluster Id information.")); + } + + // Execution with Null ApplicationId + + applicationHomeSubCluster = + ApplicationHomeSubCluster.newInstance(appIdNull, subClusterIdCorrect); + try { + AddApplicationHomeSubClusterRequest request = + AddApplicationHomeSubClusterRequest + .newInstance(applicationHomeSubCluster); + FederationApplicationInputValidator + .validateAddApplicationHomeSubClusterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + Assert.assertTrue(e.getMessage().startsWith("Missing Application Id.")); + } + } + + @Test + public void testUpdateApplicationHomeSubClusterRequestCorrect() { + + // Execution with valid inputs + + ApplicationHomeSubCluster applicationHomeSubCluster = + ApplicationHomeSubCluster.newInstance(appIdCorrect, + subClusterIdCorrect); + try { + UpdateApplicationHomeSubClusterRequest request = + UpdateApplicationHomeSubClusterRequest + .newInstance(applicationHomeSubCluster); + FederationApplicationInputValidator + .validateUpdateApplicationHomeSubClusterRequest(request); + } catch (FederationStateStoreInvalidInputException e) { + Assert.fail(e.getMessage()); + } + + // Execution with null request + + try { + UpdateApplicationHomeSubClusterRequest request = null; + FederationApplicationInputValidator + .validateUpdateApplicationHomeSubClusterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + Assert.assertTrue(e.getMessage() + .startsWith("Missing UpdateApplicationHomeSubCluster Request.")); + } + + // Execution with null ApplicationHomeSubCluster + + applicationHomeSubCluster = null; + try { + UpdateApplicationHomeSubClusterRequest request = + UpdateApplicationHomeSubClusterRequest + .newInstance(applicationHomeSubCluster); + FederationApplicationInputValidator + .validateUpdateApplicationHomeSubClusterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + Assert.assertTrue( + e.getMessage().startsWith("Missing ApplicationHomeSubCluster Info.")); + } + + // Execution with invalid SubClusterId + + applicationHomeSubCluster = ApplicationHomeSubCluster + .newInstance(appIdCorrect, subClusterIdInvalid); + try { + UpdateApplicationHomeSubClusterRequest request = + UpdateApplicationHomeSubClusterRequest + .newInstance(applicationHomeSubCluster); + FederationApplicationInputValidator + .validateUpdateApplicationHomeSubClusterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Invalid Subcluster Id information.")); + } + + // Execution with null SubClusteId + + applicationHomeSubCluster = + ApplicationHomeSubCluster.newInstance(appIdCorrect, subClusterIdNull); + try { + UpdateApplicationHomeSubClusterRequest request = + UpdateApplicationHomeSubClusterRequest + .newInstance(applicationHomeSubCluster); + FederationApplicationInputValidator + .validateUpdateApplicationHomeSubClusterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + LOG.info(e.getMessage()); + Assert.assertTrue( + e.getMessage().startsWith("Missing Subcluster Id information.")); + } + + // Execution with null ApplicationId + + applicationHomeSubCluster = + ApplicationHomeSubCluster.newInstance(appIdNull, subClusterIdCorrect); + try { + UpdateApplicationHomeSubClusterRequest request = + UpdateApplicationHomeSubClusterRequest + .newInstance(applicationHomeSubCluster); + FederationApplicationInputValidator + .validateUpdateApplicationHomeSubClusterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + Assert.assertTrue(e.getMessage().startsWith("Missing Application Id.")); + } + } + + @Test + public void testGetApplicationHomeSubClusterRequestCorrect() { + + // Execution with valid inputs + + try { + GetApplicationHomeSubClusterRequest request = + GetApplicationHomeSubClusterRequest.newInstance(appIdCorrect); + FederationApplicationInputValidator + .validateGetApplicationHomeSubClusterRequest(request); + } catch (FederationStateStoreInvalidInputException e) { + Assert.fail(e.getMessage()); + } + + // Execution with null request + + try { + GetApplicationHomeSubClusterRequest request = null; + FederationApplicationInputValidator + .validateGetApplicationHomeSubClusterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + Assert.assertTrue(e.getMessage() + .startsWith("Missing GetApplicationHomeSubCluster Request.")); + } + + // Execution with null ApplicationId + + try { + GetApplicationHomeSubClusterRequest request = + GetApplicationHomeSubClusterRequest.newInstance(appIdNull); + FederationApplicationInputValidator + .validateGetApplicationHomeSubClusterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + Assert.assertTrue(e.getMessage().startsWith("Missing Application Id.")); + } + + } + + @Test + public void testDeleteApplicationHomeSubClusterRequestNull() { + + // Execution with valid inputs + + try { + DeleteApplicationHomeSubClusterRequest request = + DeleteApplicationHomeSubClusterRequest.newInstance(appIdCorrect); + FederationApplicationInputValidator + .validateDeleteApplicationHomeSubClusterRequest(request); + } catch (FederationStateStoreInvalidInputException e) { + Assert.fail(e.getMessage()); + } + + // Execution with null request + + try { + DeleteApplicationHomeSubClusterRequest request = null; + FederationApplicationInputValidator + .validateDeleteApplicationHomeSubClusterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + Assert.assertTrue(e.getMessage() + .startsWith("Missing DeleteApplicationHomeSubCluster Request.")); + } + + // Execution with null ApplicationId + + try { + DeleteApplicationHomeSubClusterRequest request = + DeleteApplicationHomeSubClusterRequest.newInstance(appIdNull); + FederationApplicationInputValidator + .validateDeleteApplicationHomeSubClusterRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + Assert.assertTrue(e.getMessage().startsWith("Missing Application Id.")); + } + + } + + @Test + public void testGetSubClusterPolicyConfigurationRequestCorrect() { + + // Execution with valid inputs + + try { + GetSubClusterPolicyConfigurationRequest request = + GetSubClusterPolicyConfigurationRequest.newInstance(queueCorrect); + FederationPolicyInputValidator + .validateGetSubClusterPolicyConfigurationRequest(request); + } catch (FederationStateStoreInvalidInputException e) { + Assert.fail(e.getMessage()); + } + + // Execution with null request + + try { + GetSubClusterPolicyConfigurationRequest request = null; + FederationPolicyInputValidator + .validateGetSubClusterPolicyConfigurationRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + Assert.assertTrue(e.getMessage() + .startsWith("Missing GetSubClusterPolicyConfiguration Request.")); + } + + // Execution with empty queue id + + try { + GetSubClusterPolicyConfigurationRequest request = + GetSubClusterPolicyConfigurationRequest.newInstance(queueEmpty); + FederationPolicyInputValidator + .validateGetSubClusterPolicyConfigurationRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + Assert.assertTrue(e.getMessage().startsWith("Missing Queue Id.")); + } + + // Execution with null queue id + + try { + GetSubClusterPolicyConfigurationRequest request = + GetSubClusterPolicyConfigurationRequest.newInstance(queueNull); + FederationPolicyInputValidator + .validateGetSubClusterPolicyConfigurationRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + Assert.assertTrue(e.getMessage().startsWith("Missing Queue Id.")); + } + } + + @Test + public void testSetSubClusterPolicyConfigurationRequestCorrect() { + + // Execution with valid inputs + + try { + SubClusterPolicyConfiguration policy = SubClusterPolicyConfiguration + .newInstance(queueCorrect, typeCorrect, params); + SetSubClusterPolicyConfigurationRequest request = + SetSubClusterPolicyConfigurationRequest.newInstance(policy); + FederationPolicyInputValidator + .validateSetSubClusterPolicyConfigurationRequest(request); + } catch (FederationStateStoreInvalidInputException e) { + Assert.fail(e.getMessage()); + } + + // Execution with null request + + try { + SetSubClusterPolicyConfigurationRequest request = null; + FederationPolicyInputValidator + .validateSetSubClusterPolicyConfigurationRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + Assert.assertTrue(e.getMessage() + .startsWith("Missing SetSubClusterPolicyConfiguration Request.")); + } + + // Execution with null SubClusterPolicyConfiguration + + try { + SubClusterPolicyConfiguration policy = null; + SetSubClusterPolicyConfigurationRequest request = + SetSubClusterPolicyConfigurationRequest.newInstance(policy); + FederationPolicyInputValidator + .validateSetSubClusterPolicyConfigurationRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + Assert.assertTrue( + e.getMessage().startsWith("Missing SubClusterPolicyConfiguration.")); + } + + // Execution with empty queue id + + try { + SubClusterPolicyConfiguration policy = SubClusterPolicyConfiguration + .newInstance(queueEmpty, typeCorrect, params); + SetSubClusterPolicyConfigurationRequest request = + SetSubClusterPolicyConfigurationRequest.newInstance(policy); + FederationPolicyInputValidator + .validateSetSubClusterPolicyConfigurationRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + Assert.assertTrue(e.getMessage().startsWith("Missing Queue Id.")); + } + + // Execution with null queue id + + try { + SubClusterPolicyConfiguration policy = SubClusterPolicyConfiguration + .newInstance(queueNull, typeCorrect, params); + SetSubClusterPolicyConfigurationRequest request = + SetSubClusterPolicyConfigurationRequest.newInstance(policy); + FederationPolicyInputValidator + .validateSetSubClusterPolicyConfigurationRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + Assert.assertTrue(e.getMessage().startsWith("Missing Queue Id.")); + } + + // Execution with empty policy type + + try { + SubClusterPolicyConfiguration policy = SubClusterPolicyConfiguration + .newInstance(queueCorrect, typeEmpty, params); + SetSubClusterPolicyConfigurationRequest request = + SetSubClusterPolicyConfigurationRequest.newInstance(policy); + FederationPolicyInputValidator + .validateSetSubClusterPolicyConfigurationRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + Assert.assertTrue(e.getMessage().startsWith("Missing Policy Type.")); + } + + // Execution with null policy type + + try { + SubClusterPolicyConfiguration policy = SubClusterPolicyConfiguration + .newInstance(queueCorrect, typeNull, params); + SetSubClusterPolicyConfigurationRequest request = + SetSubClusterPolicyConfigurationRequest.newInstance(policy); + FederationPolicyInputValidator + .validateSetSubClusterPolicyConfigurationRequest(request); + Assert.fail(); + } catch (FederationStateStoreInvalidInputException e) { + Assert.assertTrue(e.getMessage().startsWith("Missing Policy Type.")); + } + } + +}