You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2018/06/25 19:05:57 UTC
[airavata] branch group-based-auth updated: AIRAVATA-2839 Require
unique login or allocation number
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch group-based-auth
in repository https://gitbox.apache.org/repos/asf/airavata.git
The following commit(s) were added to refs/heads/group-based-auth by this push:
new f2be221 AIRAVATA-2839 Require unique login or allocation number
f2be221 is described below
commit f2be22156d029b4c9c411780d6959baae5bc9610
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Mon Jun 25 15:03:41 2018 -0400
AIRAVATA-2839 Require unique login or allocation number
A GroupComputeResourcePreference should either specify a unique login
username or an allocation number so that jobs submitted with a
GroupResourceProfile aren't charged to default values in the
GatewayResourceProfile.
---
.../airavata/gfac/core/context/ProcessContext.java | 2 +-
.../appcatalog/ComputeResourcePreferencePK.java | 5 +
.../appcatalog/GroupResourceProfileRepository.java | 2 +
.../appcatalog/GrpComputePrefRepository.java | 30 ++
.../appcatalog/GrpComputePrefRepositoryTest.java | 440 +++++++++++++++++++++
5 files changed, 478 insertions(+), 1 deletion(-)
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/context/ProcessContext.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/context/ProcessContext.java
index 296f0da..83e5ec0 100644
--- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/context/ProcessContext.java
+++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/context/ProcessContext.java
@@ -727,7 +727,7 @@ getComputeResourceCredentialToken());
isValid(groupComputeResourcePreference.getAllocationProjectNumber())){
return groupComputeResourcePreference.getAllocationProjectNumber();
} else {
- return gatewayComputeResourcePreference.getAllocationProjectNumber();
+ return null;
}
}
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/ComputeResourcePreferencePK.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/ComputeResourcePreferencePK.java
index d49acc6..952fdbd 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/ComputeResourcePreferencePK.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/appcatalog/ComputeResourcePreferencePK.java
@@ -35,6 +35,11 @@ public class ComputeResourcePreferencePK implements Serializable {
public ComputeResourcePreferencePK() {
}
+ public ComputeResourcePreferencePK(String gatewayId, String computeResourceId) {
+ this.gatewayId = gatewayId;
+ this.computeResourceId = computeResourceId;
+ }
+
public String getGatewayId() {
return gatewayId;
}
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/GroupResourceProfileRepository.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/GroupResourceProfileRepository.java
index 3c9a401..04881dd 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/GroupResourceProfileRepository.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/GroupResourceProfileRepository.java
@@ -56,7 +56,9 @@ public class GroupResourceProfileRepository extends AppCatAbstractRepository<Gro
private void updateChildren(GroupResourceProfile groupResourceProfile, String groupResourceProfileId) {
if (groupResourceProfile.getComputePreferences() != null) {
+ GrpComputePrefRepository grpComputePrefRepository = new GrpComputePrefRepository();
for (GroupComputeResourcePreference groupComputeResourcePreference: groupResourceProfile.getComputePreferences()) {
+ grpComputePrefRepository.validateGroupComputeResourcePreference(groupComputeResourcePreference, groupResourceProfile.getGatewayId());
groupComputeResourcePreference.setGroupResourceProfileId(groupResourceProfileId);
if (groupComputeResourcePreference.getGroupSSHAccountProvisionerConfigs() != null) {
groupComputeResourcePreference.getGroupSSHAccountProvisionerConfigs().forEach(gssh -> gssh.setGroupResourceProfileId(groupResourceProfileId));
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/GrpComputePrefRepository.java b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/GrpComputePrefRepository.java
index a9ef6a3..b9c80cd 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/GrpComputePrefRepository.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/GrpComputePrefRepository.java
@@ -19,9 +19,13 @@
*/
package org.apache.airavata.registry.core.repositories.appcatalog;
+import org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference;
import org.apache.airavata.model.appcatalog.groupresourceprofile.GroupComputeResourcePreference;
+import org.apache.airavata.model.appcatalog.groupresourceprofile.GroupResourceProfile;
+import org.apache.airavata.registry.core.entities.appcatalog.ComputeResourcePreferencePK;
import org.apache.airavata.registry.core.entities.appcatalog.GroupComputeResourcePrefEntity;
import org.apache.airavata.registry.core.entities.appcatalog.GroupComputeResourcePrefPK;
+import org.apache.commons.lang3.StringUtils;
/**
* Created by skariyat on 2/10/18.
@@ -31,4 +35,30 @@ public class GrpComputePrefRepository extends AppCatAbstractRepository<GroupComp
public GrpComputePrefRepository() {
super(GroupComputeResourcePreference.class, GroupComputeResourcePrefEntity.class);
}
+
+ public void validateGroupComputeResourcePreference(GroupComputeResourcePreference groupComputeResourcePreference, String gatewayId) {
+ final String computeResourceId = groupComputeResourcePreference.getComputeResourceId();
+ final ComputeResourcePrefRepository computeResourcePrefRepository = new ComputeResourcePrefRepository();
+ ComputeResourcePreference computeResourcePreference = computeResourcePrefRepository.get(new ComputeResourcePreferencePK(gatewayId, computeResourceId));
+ if (computeResourcePreference != null) {
+ final String loginUserName = groupComputeResourcePreference.getLoginUserName();
+ boolean loginUserNameDiffers = StringUtils.isNotBlank(loginUserName) && !loginUserName.equals(computeResourcePreference.getLoginUserName());
+ boolean allocationProjectNumberNotBlankUsingSameLoginUserName = StringUtils.isNotBlank(groupComputeResourcePreference.getAllocationProjectNumber()) && StringUtils.isNotBlank(computeResourcePreference.getLoginUserName());
+ // Either loginUserName must differ from the corresponding ComputeResourcePreference
+ // or allocationProjectNumber should not be blank if using login credentials from computeResourcePreference
+ if (!loginUserNameDiffers && !allocationProjectNumberNotBlankUsingSameLoginUserName) {
+ throw new RuntimeException("loginUserName must differ from ComputeResourcePreference or " +
+ "allocationProjectNumber should not be blank. GroupResourceProfile "
+ + groupComputeResourcePreference.getGroupResourceProfileId()
+ + " for compute resource " + computeResourceId);
+ }
+ }
+ }
+
+ @Override
+ public GroupComputeResourcePreference update(GroupComputeResourcePreference computeResourcePreference) {
+ GroupResourceProfile groupResourceProfile = (new GroupResourceProfileRepository()).getGroupResourceProfile(computeResourcePreference.getGroupResourceProfileId());
+ validateGroupComputeResourcePreference(computeResourcePreference, groupResourceProfile.getGatewayId());
+ return super.update(computeResourcePreference);
+ }
}
diff --git a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/appcatalog/GrpComputePrefRepositoryTest.java b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/appcatalog/GrpComputePrefRepositoryTest.java
new file mode 100644
index 0000000..d7a1d79
--- /dev/null
+++ b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/appcatalog/GrpComputePrefRepositoryTest.java
@@ -0,0 +1,440 @@
+/*
+ * 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.airavata.registry.core.repositories.appcatalog;
+
+import org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription;
+import org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference;
+import org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile;
+import org.apache.airavata.model.appcatalog.groupresourceprofile.GroupComputeResourcePreference;
+import org.apache.airavata.model.appcatalog.groupresourceprofile.GroupResourceProfile;
+import org.apache.airavata.registry.core.repositories.common.TestBase;
+import org.apache.airavata.registry.cpi.AppCatalogException;
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class GrpComputePrefRepositoryTest extends TestBase {
+ private static final Logger logger = LoggerFactory.getLogger(ComputeResourceRepository.class);
+ private final GrpComputePrefRepository grpComputePrefRepository = new GrpComputePrefRepository();
+ private final ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository();
+ private final GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository();
+ private final GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository();
+
+ public GrpComputePrefRepositoryTest() {
+ super(Database.APP_CATALOG);
+ }
+
+ @Test
+ public void testGwyNoLoginUserNameAndGroupComputePrefNoLoginUserNameFailsValidation() throws AppCatalogException {
+
+ ComputeResourceDescription description = new ComputeResourceDescription();
+ description.setHostName("test-compute-hostname");
+ String computeResourceId = computeResourceRepository.addComputeResource(description);
+ description.setComputeResourceId(computeResourceId);
+
+ final String gatewayId = "test-gateway-id";
+ GatewayResourceProfile gatewayResourceProfile = new GatewayResourceProfile();
+ gatewayResourceProfile.setGatewayID(gatewayId);
+ ComputeResourcePreference computeResourcePreference = new ComputeResourcePreference();
+ computeResourcePreference.setComputeResourceId(computeResourceId);
+ gatewayResourceProfile.addToComputeResourcePreferences(computeResourcePreference);
+
+ gwyResourceProfileRepository.addGatewayResourceProfile(gatewayResourceProfile);
+
+ GroupComputeResourcePreference groupComputeResourcePreference = new GroupComputeResourcePreference();
+ groupComputeResourcePreference.setComputeResourceId(computeResourceId);
+
+ try {
+ grpComputePrefRepository.validateGroupComputeResourcePreference(groupComputeResourcePreference, gatewayId);
+ Assert.fail("Should have failed validation");
+ } catch (Exception e) {
+ }
+
+ gwyResourceProfileRepository.removeComputeResourcePreferenceFromGateway(gatewayId, computeResourceId);
+ gwyResourceProfileRepository.removeGatewayResourceProfile(gatewayId);
+ computeResourceRepository.removeComputeResource(computeResourceId);
+ }
+
+ @Test
+ public void testGwyNoLoginUserNameAndGroupComputePrefHasLoginUserNamePassesValidation() throws AppCatalogException {
+
+ ComputeResourceDescription description = new ComputeResourceDescription();
+ description.setHostName("test-compute-hostname");
+ String computeResourceId = computeResourceRepository.addComputeResource(description);
+ description.setComputeResourceId(computeResourceId);
+
+ final String gatewayId = "test-gateway-id";
+ final String loginUserName = "test-login-username";
+ GatewayResourceProfile gatewayResourceProfile = new GatewayResourceProfile();
+ gatewayResourceProfile.setGatewayID(gatewayId);
+ ComputeResourcePreference computeResourcePreference = new ComputeResourcePreference();
+ computeResourcePreference.setComputeResourceId(computeResourceId);
+ gatewayResourceProfile.addToComputeResourcePreferences(computeResourcePreference);
+
+ gwyResourceProfileRepository.addGatewayResourceProfile(gatewayResourceProfile);
+
+ GroupComputeResourcePreference groupComputeResourcePreference = new GroupComputeResourcePreference();
+ groupComputeResourcePreference.setComputeResourceId(computeResourceId);
+ groupComputeResourcePreference.setLoginUserName(loginUserName);
+
+ try {
+ grpComputePrefRepository.validateGroupComputeResourcePreference(groupComputeResourcePreference, gatewayId);
+ } catch (Exception e) {
+ Assert.fail("Should have passed validation");
+ }
+
+ gwyResourceProfileRepository.removeComputeResourcePreferenceFromGateway(gatewayId, computeResourceId);
+ gwyResourceProfileRepository.removeGatewayResourceProfile(gatewayId);
+ computeResourceRepository.removeComputeResource(computeResourceId);
+ }
+
+ @Test
+ public void testGwyNoLoginUserNameAndGroupComputePrefNoLoginUserNameHasAllocationNumberFailsValidation() throws AppCatalogException {
+
+ ComputeResourceDescription description = new ComputeResourceDescription();
+ description.setHostName("test-compute-hostname");
+ String computeResourceId = computeResourceRepository.addComputeResource(description);
+ description.setComputeResourceId(computeResourceId);
+
+ final String gatewayId = "test-gateway-id";
+ GatewayResourceProfile gatewayResourceProfile = new GatewayResourceProfile();
+ gatewayResourceProfile.setGatewayID(gatewayId);
+ ComputeResourcePreference computeResourcePreference = new ComputeResourcePreference();
+ computeResourcePreference.setComputeResourceId(computeResourceId);
+ gatewayResourceProfile.addToComputeResourcePreferences(computeResourcePreference);
+
+ gwyResourceProfileRepository.addGatewayResourceProfile(gatewayResourceProfile);
+
+ final String allocationProjectNumber = "test-allocation-number";
+ GroupComputeResourcePreference groupComputeResourcePreference = new GroupComputeResourcePreference();
+ groupComputeResourcePreference.setComputeResourceId(computeResourceId);
+ groupComputeResourcePreference.setAllocationProjectNumber(allocationProjectNumber);
+
+ try {
+ grpComputePrefRepository.validateGroupComputeResourcePreference(groupComputeResourcePreference, gatewayId);
+ Assert.fail("Should have failed validation");
+ } catch (Exception e) {
+ }
+
+ gwyResourceProfileRepository.removeComputeResourcePreferenceFromGateway(gatewayId, computeResourceId);
+ gwyResourceProfileRepository.removeGatewayResourceProfile(gatewayId);
+ computeResourceRepository.removeComputeResource(computeResourceId);
+ }
+
+ @Test
+ public void testGwyHasLoginUserNameAndGroupComputePrefNoLoginUserNameFailsValidation() throws AppCatalogException {
+
+ ComputeResourceDescription description = new ComputeResourceDescription();
+ description.setHostName("test-compute-hostname");
+ String computeResourceId = computeResourceRepository.addComputeResource(description);
+ description.setComputeResourceId(computeResourceId);
+
+ final String gatewayId = "test-gateway-id";
+ final String loginUserName = "test-login-username";
+ GatewayResourceProfile gatewayResourceProfile = new GatewayResourceProfile();
+ gatewayResourceProfile.setGatewayID(gatewayId);
+ ComputeResourcePreference computeResourcePreference = new ComputeResourcePreference();
+ computeResourcePreference.setComputeResourceId(computeResourceId);
+ computeResourcePreference.setLoginUserName(loginUserName);
+ gatewayResourceProfile.addToComputeResourcePreferences(computeResourcePreference);
+
+ gwyResourceProfileRepository.addGatewayResourceProfile(gatewayResourceProfile);
+
+ GroupComputeResourcePreference groupComputeResourcePreference = new GroupComputeResourcePreference();
+ groupComputeResourcePreference.setComputeResourceId(computeResourceId);
+
+ try {
+ grpComputePrefRepository.validateGroupComputeResourcePreference(groupComputeResourcePreference, gatewayId);
+ Assert.fail("Should have failed validation");
+ } catch (Exception e) {
+ }
+
+ gwyResourceProfileRepository.removeComputeResourcePreferenceFromGateway(gatewayId, computeResourceId);
+ gwyResourceProfileRepository.removeGatewayResourceProfile(gatewayId);
+ computeResourceRepository.removeComputeResource(computeResourceId);
+ }
+
+ @Test
+ public void testGwyHasLoginUserNameAndGroupComputePrefHasSameLoginUserNameFailsValidation() throws AppCatalogException {
+
+ ComputeResourceDescription description = new ComputeResourceDescription();
+ description.setHostName("test-compute-hostname");
+ String computeResourceId = computeResourceRepository.addComputeResource(description);
+ description.setComputeResourceId(computeResourceId);
+
+ final String gatewayId = "test-gateway-id";
+ final String loginUserName = "test-login-username";
+ GatewayResourceProfile gatewayResourceProfile = new GatewayResourceProfile();
+ gatewayResourceProfile.setGatewayID(gatewayId);
+ ComputeResourcePreference computeResourcePreference = new ComputeResourcePreference();
+ computeResourcePreference.setComputeResourceId(computeResourceId);
+ computeResourcePreference.setLoginUserName(loginUserName);
+ gatewayResourceProfile.addToComputeResourcePreferences(computeResourcePreference);
+
+ gwyResourceProfileRepository.addGatewayResourceProfile(gatewayResourceProfile);
+
+ GroupComputeResourcePreference groupComputeResourcePreference = new GroupComputeResourcePreference();
+ groupComputeResourcePreference.setComputeResourceId(computeResourceId);
+ groupComputeResourcePreference.setLoginUserName(loginUserName);
+ Assert.assertEquals(groupComputeResourcePreference.getLoginUserName(), computeResourcePreference.getLoginUserName());
+
+ try {
+ grpComputePrefRepository.validateGroupComputeResourcePreference(groupComputeResourcePreference, gatewayId);
+ Assert.fail("Should have failed validation");
+ } catch (Exception e) {
+ }
+
+ gwyResourceProfileRepository.removeComputeResourcePreferenceFromGateway(gatewayId, computeResourceId);
+ gwyResourceProfileRepository.removeGatewayResourceProfile(gatewayId);
+ computeResourceRepository.removeComputeResource(computeResourceId);
+ }
+
+ @Test
+ public void testGwyHasLoginUserNameAndGroupComputePrefNoLoginUserNameHasAllocationNumberPassesValidation() throws AppCatalogException {
+
+ ComputeResourceDescription description = new ComputeResourceDescription();
+ description.setHostName("test-compute-hostname");
+ String computeResourceId = computeResourceRepository.addComputeResource(description);
+ description.setComputeResourceId(computeResourceId);
+
+ final String gatewayId = "test-gateway-id";
+ final String loginUserName = "test-login-username";
+ GatewayResourceProfile gatewayResourceProfile = new GatewayResourceProfile();
+ gatewayResourceProfile.setGatewayID(gatewayId);
+ ComputeResourcePreference computeResourcePreference = new ComputeResourcePreference();
+ computeResourcePreference.setComputeResourceId(computeResourceId);
+ computeResourcePreference.setLoginUserName(loginUserName);
+ gatewayResourceProfile.addToComputeResourcePreferences(computeResourcePreference);
+
+ gwyResourceProfileRepository.addGatewayResourceProfile(gatewayResourceProfile);
+
+ final String allocationProjectNumber = "test-allocation-project-number";
+ GroupComputeResourcePreference groupComputeResourcePreference = new GroupComputeResourcePreference();
+ groupComputeResourcePreference.setComputeResourceId(computeResourceId);
+ groupComputeResourcePreference.setAllocationProjectNumber(allocationProjectNumber);
+
+ try {
+ grpComputePrefRepository.validateGroupComputeResourcePreference(groupComputeResourcePreference, gatewayId);
+ } catch (Exception e) {
+ Assert.fail("Should have passed validation");
+ }
+
+ gwyResourceProfileRepository.removeComputeResourcePreferenceFromGateway(gatewayId, computeResourceId);
+ gwyResourceProfileRepository.removeGatewayResourceProfile(gatewayId);
+ computeResourceRepository.removeComputeResource(computeResourceId);
+ }
+
+ @Test
+ public void testGwyHasLoginUserNameAndGroupComputePrefHasSameLoginUserNameHasAllocationNumberPassesValidation() throws AppCatalogException {
+
+ ComputeResourceDescription description = new ComputeResourceDescription();
+ description.setHostName("test-compute-hostname");
+ String computeResourceId = computeResourceRepository.addComputeResource(description);
+ description.setComputeResourceId(computeResourceId);
+
+ final String gatewayId = "test-gateway-id";
+ final String loginUserName = "test-login-username";
+ GatewayResourceProfile gatewayResourceProfile = new GatewayResourceProfile();
+ gatewayResourceProfile.setGatewayID(gatewayId);
+ ComputeResourcePreference computeResourcePreference = new ComputeResourcePreference();
+ computeResourcePreference.setComputeResourceId(computeResourceId);
+ computeResourcePreference.setLoginUserName(loginUserName);
+ gatewayResourceProfile.addToComputeResourcePreferences(computeResourcePreference);
+
+ gwyResourceProfileRepository.addGatewayResourceProfile(gatewayResourceProfile);
+
+ final String allocationProjectNumber = "test-allocation-project-number";
+ GroupComputeResourcePreference groupComputeResourcePreference = new GroupComputeResourcePreference();
+ groupComputeResourcePreference.setComputeResourceId(computeResourceId);
+ groupComputeResourcePreference.setLoginUserName(loginUserName);
+ groupComputeResourcePreference.setAllocationProjectNumber(allocationProjectNumber);
+ Assert.assertEquals(groupComputeResourcePreference.getLoginUserName(), computeResourcePreference.getLoginUserName());
+
+ try {
+ grpComputePrefRepository.validateGroupComputeResourcePreference(groupComputeResourcePreference, gatewayId);
+ } catch (Exception e) {
+ Assert.fail("Should have passed validation");
+ }
+
+ gwyResourceProfileRepository.removeComputeResourcePreferenceFromGateway(gatewayId, computeResourceId);
+ gwyResourceProfileRepository.removeGatewayResourceProfile(gatewayId);
+ computeResourceRepository.removeComputeResource(computeResourceId);
+ }
+
+ @Test
+ public void testGwyHasLoginUserNameAndGroupComputePrefHasDifferentLoginUserNameHasAllocationNumberPassesValidation() throws AppCatalogException {
+
+ ComputeResourceDescription description = new ComputeResourceDescription();
+ description.setHostName("test-compute-hostname");
+ String computeResourceId = computeResourceRepository.addComputeResource(description);
+ description.setComputeResourceId(computeResourceId);
+
+ final String gatewayId = "test-gateway-id";
+ final String loginUserName = "test-login-username";
+ GatewayResourceProfile gatewayResourceProfile = new GatewayResourceProfile();
+ gatewayResourceProfile.setGatewayID(gatewayId);
+ ComputeResourcePreference computeResourcePreference = new ComputeResourcePreference();
+ computeResourcePreference.setComputeResourceId(computeResourceId);
+ computeResourcePreference.setLoginUserName(loginUserName);
+ gatewayResourceProfile.addToComputeResourcePreferences(computeResourcePreference);
+
+ gwyResourceProfileRepository.addGatewayResourceProfile(gatewayResourceProfile);
+
+ final String allocationProjectNumber = "test-allocation-project-number";
+ GroupComputeResourcePreference groupComputeResourcePreference = new GroupComputeResourcePreference();
+ groupComputeResourcePreference.setComputeResourceId(computeResourceId);
+ groupComputeResourcePreference.setLoginUserName("test-login-username2");
+ groupComputeResourcePreference.setAllocationProjectNumber(allocationProjectNumber);
+ Assert.assertNotEquals(groupComputeResourcePreference.getLoginUserName(), computeResourcePreference.getLoginUserName());
+
+ try {
+ grpComputePrefRepository.validateGroupComputeResourcePreference(groupComputeResourcePreference, gatewayId);
+ } catch (Exception e) {
+ Assert.fail("Should have passed validation");
+ }
+
+ gwyResourceProfileRepository.removeComputeResourcePreferenceFromGateway(gatewayId, computeResourceId);
+ gwyResourceProfileRepository.removeGatewayResourceProfile(gatewayId);
+ computeResourceRepository.removeComputeResource(computeResourceId);
+ }
+
+ @Test
+ public void testGwyHasLoginUserNameAndGroupComputePrefHasDifferentLoginUserNamePassesValidation() throws AppCatalogException {
+
+ ComputeResourceDescription description = new ComputeResourceDescription();
+ description.setHostName("test-compute-hostname");
+ String computeResourceId = computeResourceRepository.addComputeResource(description);
+ description.setComputeResourceId(computeResourceId);
+
+ final String gatewayId = "test-gateway-id";
+ final String loginUserName = "test-login-username";
+ GatewayResourceProfile gatewayResourceProfile = new GatewayResourceProfile();
+ gatewayResourceProfile.setGatewayID(gatewayId);
+ ComputeResourcePreference computeResourcePreference = new ComputeResourcePreference();
+ computeResourcePreference.setComputeResourceId(computeResourceId);
+ computeResourcePreference.setLoginUserName(loginUserName);
+ gatewayResourceProfile.addToComputeResourcePreferences(computeResourcePreference);
+
+ gwyResourceProfileRepository.addGatewayResourceProfile(gatewayResourceProfile);
+
+ GroupComputeResourcePreference groupComputeResourcePreference = new GroupComputeResourcePreference();
+ groupComputeResourcePreference.setComputeResourceId(computeResourceId);
+ groupComputeResourcePreference.setLoginUserName("test-login-username2");
+ Assert.assertNotEquals(groupComputeResourcePreference.getLoginUserName(), computeResourcePreference.getLoginUserName());
+
+ try {
+ grpComputePrefRepository.validateGroupComputeResourcePreference(groupComputeResourcePreference, gatewayId);
+ } catch (Exception e) {
+ Assert.fail("Should have passed validation");
+ }
+
+ gwyResourceProfileRepository.removeComputeResourcePreferenceFromGateway(gatewayId, computeResourceId);
+ gwyResourceProfileRepository.removeGatewayResourceProfile(gatewayId);
+ computeResourceRepository.removeComputeResource(computeResourceId);
+ }
+
+ @Test
+ public void testCreateCallsValidationAndFailsValidation() throws AppCatalogException {
+
+ ComputeResourceDescription description = new ComputeResourceDescription();
+ description.setHostName("test-compute-hostname");
+ String computeResourceId = computeResourceRepository.addComputeResource(description);
+ description.setComputeResourceId(computeResourceId);
+
+ final String gatewayId = "test-gateway-id";
+ final String loginUserName = "test-login-username";
+ GatewayResourceProfile gatewayResourceProfile = new GatewayResourceProfile();
+ gatewayResourceProfile.setGatewayID(gatewayId);
+ ComputeResourcePreference computeResourcePreference = new ComputeResourcePreference();
+ computeResourcePreference.setComputeResourceId(computeResourceId);
+ computeResourcePreference.setLoginUserName(loginUserName);
+ gatewayResourceProfile.addToComputeResourcePreferences(computeResourcePreference);
+
+ gwyResourceProfileRepository.addGatewayResourceProfile(gatewayResourceProfile);
+
+ GroupResourceProfile groupResourceProfile = new GroupResourceProfile();
+ groupResourceProfile.setGatewayId(gatewayId);
+ String groupResourceProfileId = groupResourceProfileRepository.addGroupResourceProfile(groupResourceProfile);
+ groupResourceProfile.setGroupResourceProfileId(groupResourceProfileId);
+
+ GroupComputeResourcePreference groupComputeResourcePreference = new GroupComputeResourcePreference();
+ groupComputeResourcePreference.setGroupResourceProfileId(groupResourceProfileId);
+ groupComputeResourcePreference.setComputeResourceId(computeResourceId);
+ groupComputeResourcePreference.setLoginUserName(loginUserName);
+ Assert.assertEquals(groupComputeResourcePreference.getLoginUserName(), computeResourcePreference.getLoginUserName());
+
+ try {
+ grpComputePrefRepository.create(groupComputeResourcePreference);
+ Assert.fail("Should have failed validation");
+ } catch (Exception e) {
+ }
+
+ gwyResourceProfileRepository.removeComputeResourcePreferenceFromGateway(gatewayId, computeResourceId);
+ gwyResourceProfileRepository.removeGatewayResourceProfile(gatewayId);
+ computeResourceRepository.removeComputeResource(computeResourceId);
+ }
+
+ @Test
+ public void testUpdateCallsValidationAndFailsValidation() throws AppCatalogException {
+
+ ComputeResourceDescription description = new ComputeResourceDescription();
+ description.setHostName("test-compute-hostname");
+ String computeResourceId = computeResourceRepository.addComputeResource(description);
+ description.setComputeResourceId(computeResourceId);
+
+ final String gatewayId = "test-gateway-id";
+ final String loginUserName = "test-login-username";
+ GatewayResourceProfile gatewayResourceProfile = new GatewayResourceProfile();
+ gatewayResourceProfile.setGatewayID(gatewayId);
+ ComputeResourcePreference computeResourcePreference = new ComputeResourcePreference();
+ computeResourcePreference.setComputeResourceId(computeResourceId);
+ computeResourcePreference.setLoginUserName(loginUserName);
+ gatewayResourceProfile.addToComputeResourcePreferences(computeResourcePreference);
+
+ gwyResourceProfileRepository.addGatewayResourceProfile(gatewayResourceProfile);
+
+ GroupResourceProfile groupResourceProfile = new GroupResourceProfile();
+ groupResourceProfile.setGatewayId(gatewayId);
+ String groupResourceProfileId = groupResourceProfileRepository.addGroupResourceProfile(groupResourceProfile);
+ groupResourceProfile.setGroupResourceProfileId(groupResourceProfileId);
+
+ GroupComputeResourcePreference groupComputeResourcePreference = new GroupComputeResourcePreference();
+ groupComputeResourcePreference.setGroupResourceProfileId(groupResourceProfileId);
+ groupComputeResourcePreference.setComputeResourceId(computeResourceId);
+ groupComputeResourcePreference.setLoginUserName("test-login-username2");
+ Assert.assertNotEquals(groupComputeResourcePreference.getLoginUserName(), computeResourcePreference.getLoginUserName());
+
+ grpComputePrefRepository.create(groupComputeResourcePreference);
+ groupComputeResourcePreference.setLoginUserName(loginUserName);
+ Assert.assertEquals(groupComputeResourcePreference.getLoginUserName(), computeResourcePreference.getLoginUserName());
+
+ try {
+ grpComputePrefRepository.update(groupComputeResourcePreference);
+ Assert.fail("Should have failed validation");
+ } catch (Exception e) {
+ }
+
+ gwyResourceProfileRepository.removeComputeResourcePreferenceFromGateway(gatewayId, computeResourceId);
+ gwyResourceProfileRepository.removeGatewayResourceProfile(gatewayId);
+ computeResourceRepository.removeComputeResource(computeResourceId);
+ }
+}