@Test public void shouldShortenGcpInstanceGroupNameWhenLongResourceNameProvided() { Object[] parts = {"stackname", "thisisareallylonginstancenamewhichwillbeshortenedbythemethod", 8999}; String resourceName = subject.resourceName(ResourceType.GCP_INSTANCE, parts); Assert.assertNotNull("The generated name must not be null!", resourceName); Assert.assertEquals("The timestamp must be appended!", 4L, resourceName.split("-").length); Assert.assertEquals("The resource name suffix is not the excepted one!", "stackname", resourceName.split("-")[0]); Assert.assertEquals("The instance group name is not the excepted one!", "t", resourceName.split("-")[1]); Assert.assertEquals("The private is not the excepted one!", "8999", resourceName.split("-")[2]); Assert.assertTrue("The resource name length is wrong", resourceName.length() < Integer.parseInt(MAX_RESOURCE_NAME_LENGTH)); }
@Override public String resourceName(ResourceType resourceType, Object... parts) { String resourceName; switch (resourceType) { case GCP_NETWORK: resourceName = gcpNetworkResourceName(parts); break; case GCP_SUBNET: resourceName = gcpSubnetResourceName(parts); break; case GCP_FIREWALL_INTERNAL: resourceName = stackBasedResourceWithSuffix(FIREWALL_INTERNAL_NAME_SUFFIX, parts); break; case GCP_FIREWALL_IN: resourceName = stackBasedResourceWithSuffix(FIREWALL_IN_NAME_SUFFIX, parts); break; case GCP_RESERVED_IP: resourceName = instanceName(parts); break; case GCP_INSTANCE: resourceName = instanceName(parts); break; case GCP_DISK: resourceName = instanceName(parts); break; case GCP_ATTACHED_DISKSET: resourceName = attachedDiskResourceName(parts); break; case GCP_DATABASE: resourceName = deploymentTemplateName(parts); break; default: throw new IllegalStateException("Unsupported resource type: " + resourceType); } return resourceName; }
GcpResourceNameService extends CloudbreakResourceNameService { @Override public String resourceName(ResourceType resourceType, Object... parts) { String resourceName; switch (resourceType) { case GCP_NETWORK: resourceName = gcpNetworkResourceName(parts); break; case GCP_SUBNET: resourceName = gcpSubnetResourceName(parts); break; case GCP_FIREWALL_INTERNAL: resourceName = stackBasedResourceWithSuffix(FIREWALL_INTERNAL_NAME_SUFFIX, parts); break; case GCP_FIREWALL_IN: resourceName = stackBasedResourceWithSuffix(FIREWALL_IN_NAME_SUFFIX, parts); break; case GCP_RESERVED_IP: resourceName = instanceName(parts); break; case GCP_INSTANCE: resourceName = instanceName(parts); break; case GCP_DISK: resourceName = instanceName(parts); break; case GCP_ATTACHED_DISKSET: resourceName = attachedDiskResourceName(parts); break; case GCP_DATABASE: resourceName = deploymentTemplateName(parts); break; default: throw new IllegalStateException("Unsupported resource type: " + resourceType); } return resourceName; } }
GcpResourceNameService extends CloudbreakResourceNameService { @Override public String resourceName(ResourceType resourceType, Object... parts) { String resourceName; switch (resourceType) { case GCP_NETWORK: resourceName = gcpNetworkResourceName(parts); break; case GCP_SUBNET: resourceName = gcpSubnetResourceName(parts); break; case GCP_FIREWALL_INTERNAL: resourceName = stackBasedResourceWithSuffix(FIREWALL_INTERNAL_NAME_SUFFIX, parts); break; case GCP_FIREWALL_IN: resourceName = stackBasedResourceWithSuffix(FIREWALL_IN_NAME_SUFFIX, parts); break; case GCP_RESERVED_IP: resourceName = instanceName(parts); break; case GCP_INSTANCE: resourceName = instanceName(parts); break; case GCP_DISK: resourceName = instanceName(parts); break; case GCP_ATTACHED_DISKSET: resourceName = attachedDiskResourceName(parts); break; case GCP_DATABASE: resourceName = deploymentTemplateName(parts); break; default: throw new IllegalStateException("Unsupported resource type: " + resourceType); } return resourceName; }  }
GcpResourceNameService extends CloudbreakResourceNameService { @Override public String resourceName(ResourceType resourceType, Object... parts) { String resourceName; switch (resourceType) { case GCP_NETWORK: resourceName = gcpNetworkResourceName(parts); break; case GCP_SUBNET: resourceName = gcpSubnetResourceName(parts); break; case GCP_FIREWALL_INTERNAL: resourceName = stackBasedResourceWithSuffix(FIREWALL_INTERNAL_NAME_SUFFIX, parts); break; case GCP_FIREWALL_IN: resourceName = stackBasedResourceWithSuffix(FIREWALL_IN_NAME_SUFFIX, parts); break; case GCP_RESERVED_IP: resourceName = instanceName(parts); break; case GCP_INSTANCE: resourceName = instanceName(parts); break; case GCP_DISK: resourceName = instanceName(parts); break; case GCP_ATTACHED_DISKSET: resourceName = attachedDiskResourceName(parts); break; case GCP_DATABASE: resourceName = deploymentTemplateName(parts); break; default: throw new IllegalStateException("Unsupported resource type: " + resourceType); } return resourceName; }  @Override String resourceName(ResourceType resourceType, Object... parts); }
GcpResourceNameService extends CloudbreakResourceNameService { @Override public String resourceName(ResourceType resourceType, Object... parts) { String resourceName; switch (resourceType) { case GCP_NETWORK: resourceName = gcpNetworkResourceName(parts); break; case GCP_SUBNET: resourceName = gcpSubnetResourceName(parts); break; case GCP_FIREWALL_INTERNAL: resourceName = stackBasedResourceWithSuffix(FIREWALL_INTERNAL_NAME_SUFFIX, parts); break; case GCP_FIREWALL_IN: resourceName = stackBasedResourceWithSuffix(FIREWALL_IN_NAME_SUFFIX, parts); break; case GCP_RESERVED_IP: resourceName = instanceName(parts); break; case GCP_INSTANCE: resourceName = instanceName(parts); break; case GCP_DISK: resourceName = instanceName(parts); break; case GCP_ATTACHED_DISKSET: resourceName = attachedDiskResourceName(parts); break; case GCP_DATABASE: resourceName = deploymentTemplateName(parts); break; default: throw new IllegalStateException("Unsupported resource type: " + resourceType); } return resourceName; }  @Override String resourceName(ResourceType resourceType, Object... parts);  }