Skip to content

Commit

Permalink
TOAZ-336 phase 1: Add missing Azure resources to Janitor (#168)
Browse files Browse the repository at this point in the history
* Add: Azure database and kubernetes namespace. Remove: container instance, network, nsg, publicIp, relay

* Add server name

* Tmp update settings

* Fix openapi typo

* Tests compile, need some work

* Integration tests pass now

* Put back settings
  • Loading branch information
rtitle authored Nov 4, 2023
1 parent 73098d3 commit 5cf4218
Show file tree
Hide file tree
Showing 22 changed files with 202 additions and 850 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.azure.core.management.profile.AzureProfile;
import com.azure.identity.ClientSecretCredentialBuilder;
import com.azure.resourcemanager.compute.ComputeManager;
import com.azure.resourcemanager.containerinstance.ContainerInstanceManager;
import com.azure.resourcemanager.msi.MsiManager;
import com.azure.resourcemanager.relay.RelayManager;
import com.azure.resourcemanager.storage.StorageManager;
Expand Down Expand Up @@ -108,15 +107,6 @@ public RelayManager buildRelayManager(AzureResourceGroup resourceGroup) {
.authenticate(getAzureCredential(), getAzureProfile(resourceGroup));
}

/**
* Creates an Azure {@link ContainerInstanceManager} client for a given managed resource group.
*/
public ContainerInstanceManager buildContainerInstance(AzureResourceGroup resourceGroup) {
return bio.terra.cloudres.azure.resourcemanager.common.Defaults.crlConfigure(
clientConfig, ContainerInstanceManager.configure())
.authenticate(getAzureCredential(), getAzureProfile(resourceGroup));
}

/** Creates an Azure {@link MsiManager} client for a given managed resource group. */
public MsiManager buildMsiManager(AzureResourceGroup resourceGroup) {
return bio.terra.cloudres.azure.resourcemanager.common.Defaults.crlConfigure(
Expand Down
35 changes: 10 additions & 25 deletions src/main/java/bio/terra/janitor/common/CloudResourceUidVisitor.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package bio.terra.janitor.common;

import bio.terra.janitor.generated.model.AzureContainerInstance;
import bio.terra.janitor.generated.model.AzureDatabase;
import bio.terra.janitor.generated.model.AzureDisk;
import bio.terra.janitor.generated.model.AzureKubernetesNamespace;
import bio.terra.janitor.generated.model.AzureManagedIdentity;
import bio.terra.janitor.generated.model.AzureNetwork;
import bio.terra.janitor.generated.model.AzureNetworkSecurityGroup;
import bio.terra.janitor.generated.model.AzurePublicIp;
import bio.terra.janitor.generated.model.AzureRelay;
import bio.terra.janitor.generated.model.AzureRelayHybridConnection;
import bio.terra.janitor.generated.model.AzureStorageContainer;
import bio.terra.janitor.generated.model.AzureVirtualMachine;
Expand All @@ -33,28 +30,22 @@ public interface CloudResourceUidVisitor<R> {

R visit(GoogleAiNotebookInstanceUid resource);

R visit(AzurePublicIp resource);

R visit(AzureNetworkSecurityGroup resource);

R visit(AzureNetwork resource);

R visit(AzureDisk resource);

R visit(AzureVirtualMachine resource);

R visit(AzureRelay resource);

R visit(AzureRelayHybridConnection resource);

R visit(AzureContainerInstance resource);

R visit(TerraWorkspaceUid resource);

R visit(AzureManagedIdentity resource);

R visit(AzureStorageContainer resource);

R visit(AzureDatabase resource);

R visit(AzureKubernetesNamespace resource);

R noResourceVisited(CloudResourceUid resource);

static <R> R visit(CloudResourceUid resource, CloudResourceUidVisitor<R> visitor) {
Expand All @@ -70,28 +61,22 @@ static <R> R visit(CloudResourceUid resource, CloudResourceUidVisitor<R> visitor
return visitor.visit(resource.getGoogleBigQueryTableUid());
} else if (resource.getGoogleAiNotebookInstanceUid() != null) {
return visitor.visit(resource.getGoogleAiNotebookInstanceUid());
} else if (resource.getAzurePublicIp() != null) {
return visitor.visit(resource.getAzurePublicIp());
} else if (resource.getAzureNetworkSecurityGroup() != null) {
return visitor.visit(resource.getAzureNetworkSecurityGroup());
} else if (resource.getAzureNetwork() != null) {
return visitor.visit(resource.getAzureNetwork());
} else if (resource.getAzureDisk() != null) {
return visitor.visit(resource.getAzureDisk());
} else if (resource.getAzureVirtualMachine() != null) {
return visitor.visit(resource.getAzureVirtualMachine());
} else if (resource.getAzureRelay() != null) {
return visitor.visit(resource.getAzureRelay());
} else if (resource.getAzureRelayHybridConnection() != null) {
return visitor.visit(resource.getAzureRelayHybridConnection());
} else if (resource.getAzureContainerInstance() != null) {
return visitor.visit(resource.getAzureContainerInstance());
} else if (resource.getTerraWorkspace() != null) {
return visitor.visit(resource.getTerraWorkspace());
} else if (resource.getAzureManagedIdentity() != null) {
return visitor.visit(resource.getAzureManagedIdentity());
} else if (resource.getAzureStorageContainer() != null) {
return visitor.visit(resource.getAzureStorageContainer());
} else if (resource.getAzureDatabase() != null) {
return visitor.visit(resource.getAzureDatabase());
} else if (resource.getAzureKubernetesNamespace() != null) {
return visitor.visit(resource.getAzureKubernetesNamespace());
} else {
return visitor.noResourceVisited(resource);
}
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/bio/terra/janitor/db/ResourceType.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ public enum ResourceType {
GOOGLE_BUCKET,
GOOGLE_NOTEBOOK_INSTANCE,
GOOGLE_PROJECT,
AZURE_PUBLIC_IP,
AZURE_NETWORK_SECURITY_GROUP,
AZURE_NETWORK,
AZURE_DISK,
AZURE_VIRTUAL_MACHINE,
AZURE_RELAY,
AZURE_RELAY_CONNECTION,
AZURE_CONTAINER_INSTANCE,
TERRA_WORKSPACE,
AZURE_MANAGED_IDENTITY,
AZURE_STORAGE_CONTAINER
AZURE_STORAGE_CONTAINER,
AZURE_DATABASE,
AZURE_KUBERNETES_NAMESPACE,
}
35 changes: 10 additions & 25 deletions src/main/java/bio/terra/janitor/db/ResourceTypeVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,6 @@ public ResourceType visit(GoogleAiNotebookInstanceUid resource) {
return GOOGLE_NOTEBOOK_INSTANCE;
}

@Override
public ResourceType visit(AzurePublicIp resource) {
return AZURE_PUBLIC_IP;
}

@Override
public ResourceType visit(AzureNetworkSecurityGroup resource) {
return AZURE_NETWORK_SECURITY_GROUP;
}

@Override
public ResourceType visit(AzureNetwork resource) {
return AZURE_NETWORK;
}

@Override
public ResourceType visit(AzureDisk resource) {
return AZURE_DISK;
Expand All @@ -63,21 +48,11 @@ public ResourceType visit(AzureVirtualMachine resource) {
return AZURE_VIRTUAL_MACHINE;
}

@Override
public ResourceType visit(AzureRelay resource) {
return AZURE_RELAY;
}

@Override
public ResourceType visit(AzureRelayHybridConnection resource) {
return AZURE_RELAY_CONNECTION;
}

@Override
public ResourceType visit(AzureContainerInstance resource) {
return AZURE_CONTAINER_INSTANCE;
}

@Override
public ResourceType visit(TerraWorkspaceUid resource) {
return TERRA_WORKSPACE;
Expand All @@ -93,6 +68,16 @@ public ResourceType visit(AzureStorageContainer resource) {
return AZURE_STORAGE_CONTAINER;
}

@Override
public ResourceType visit(AzureDatabase resource) {
return AZURE_DATABASE;
}

@Override
public ResourceType visit(AzureKubernetesNamespace resource) {
return AZURE_KUBERNETES_NAMESPACE;
}

@Override
public ResourceType noResourceVisited(CloudResourceUid resource) {
throw new InvalidResourceUidException("invalid CloudResourceUid for" + resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,12 @@ public FlightSubmission createSubmission(TrackedResource trackedResource) {
return FlightSubmission.create(GoogleAiNotebookInstanceCleanupFlight.class, flightMap);
case GOOGLE_PROJECT:
return FlightSubmission.create(GoogleProjectCleanupFlight.class, flightMap);
case AZURE_PUBLIC_IP:
return FlightSubmission.create(AzurePublicIpCleanupFlight.class, flightMap);
case AZURE_NETWORK_SECURITY_GROUP:
return FlightSubmission.create(AzureNetworkSecurityGroupCleanupFlight.class, flightMap);
case AZURE_NETWORK:
return FlightSubmission.create(AzureNetworkCleanupFlight.class, flightMap);
case AZURE_DISK:
return FlightSubmission.create(AzureDiskCleanupFlight.class, flightMap);
case AZURE_VIRTUAL_MACHINE:
return FlightSubmission.create(AzureVirtualMachineCleanupFlight.class, flightMap);
case AZURE_RELAY:
return FlightSubmission.create(AzureRelayCleanupFlight.class, flightMap);
case AZURE_RELAY_CONNECTION:
return FlightSubmission.create(AzureRelayHybridConnectionCleanupFlight.class, flightMap);
case AZURE_CONTAINER_INSTANCE:
return FlightSubmission.create(AzureContainerInstanceCleanupFlight.class, flightMap);
case TERRA_WORKSPACE:
return FlightSubmission.create(TerraWorkspaceCleanupFlight.class, flightMap);
case AZURE_MANAGED_IDENTITY:
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 5cf4218

Please sign in to comment.