Skip to content

Commit

Permalink
[#215] Migrate from pgsql standalone server to pgsql flexible server
Browse files Browse the repository at this point in the history
  • Loading branch information
istraka committed Jan 26, 2024
1 parent 630023b commit daaefbb
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 51 deletions.
2 changes: 1 addition & 1 deletion azure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</dependency>
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-postgresql</artifactId>
<artifactId>azure-resourcemanager-postgresqlflexibleserver</artifactId>
</dependency>

<!-- JUnit5-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.azure.resourcemanager.appservice.models.AppServicePlan;
import com.azure.resourcemanager.appservice.models.WebApp;
import com.azure.resourcemanager.compute.models.VirtualMachine;
import com.azure.resourcemanager.postgresql.PostgreSqlManager;
import com.azure.resourcemanager.postgresql.models.Server;
import com.azure.resourcemanager.postgresqlflexibleserver.PostgreSqlManager;
import com.azure.resourcemanager.postgresqlflexibleserver.models.Server;
import sunstone.azure.annotation.AzureAppServicePlan;
import sunstone.azure.annotation.AzureAutoResolve;
import sunstone.azure.annotation.AzurePgSqlServer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import com.azure.resourcemanager.appservice.models.WebApp;
import com.azure.resourcemanager.compute.models.VirtualMachine;
import com.azure.resourcemanager.postgresql.models.Server;
import com.azure.resourcemanager.postgresqlflexibleserver.models.Server;
import sunstone.inject.Hostname;
import sunstone.core.exceptions.SunstoneException;
import sunstone.core.exceptions.UnsupportedSunstoneOperationException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.azure.resourcemanager.appservice.models.AppServicePlan;
import com.azure.resourcemanager.appservice.models.WebApp;
import com.azure.resourcemanager.compute.models.VirtualMachine;
import com.azure.resourcemanager.postgresql.PostgreSqlManager;
import com.azure.resourcemanager.postgresql.models.Server;
import com.azure.resourcemanager.postgresqlflexibleserver.PostgreSqlManager;
import com.azure.resourcemanager.postgresqlflexibleserver.models.Server;
import org.junit.jupiter.api.extension.ExtensionContext;
import sunstone.inject.Hostname;
import sunstone.azure.annotation.AzureResourceIdentificationAnnotation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


import com.azure.resourcemanager.AzureResourceManager;
import com.azure.resourcemanager.postgresql.PostgreSqlManager;
import com.azure.resourcemanager.postgresqlflexibleserver.PostgreSqlManager;
import org.junit.jupiter.api.extension.ExtensionContext;
import sunstone.core.SunstoneStore;

Expand Down
4 changes: 2 additions & 2 deletions azure/src/main/java/sunstone/azure/impl/AzureUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import com.azure.resourcemanager.appservice.models.AppServicePlan;
import com.azure.resourcemanager.appservice.models.WebApp;
import com.azure.resourcemanager.compute.models.VirtualMachine;
import com.azure.resourcemanager.postgresql.PostgreSqlManager;
import com.azure.resourcemanager.postgresql.models.Server;
import com.azure.resourcemanager.postgresqlflexibleserver.PostgreSqlManager;
import com.azure.resourcemanager.postgresqlflexibleserver.models.Server;
import sunstone.core.SunstoneConfig;

import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package sunstone.azure.armTemplates.di;


import com.azure.resourcemanager.postgresql.PostgreSqlManager;
import com.azure.resourcemanager.postgresqlflexibleserver.PostgreSqlManager;
import sunstone.azure.annotation.AzureAutoResolve;
import com.azure.resourcemanager.AzureResourceManager;
import org.junit.jupiter.api.BeforeAll;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package sunstone.azure.armTemplates.di;


import com.azure.resourcemanager.postgresql.models.Server;
import com.azure.resourcemanager.postgresqlflexibleserver.models.Server;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import sunstone.annotation.Parameter;
Expand All @@ -14,14 +14,14 @@


@WithAzureArmTemplate(parameters = {
@Parameter(k = "username", v = AzPgSqlTests.PGSQL_USER),
@Parameter(k = "password", v = AzPgSqlTests.PGSQL_PASSWORD),
@Parameter(k = "administratorLogin", v = AzPgSqlTests.PGSQL_USER),
@Parameter(k = "administratorLoginPassword", v = AzPgSqlTests.PGSQL_PASSWORD),
@Parameter(k = "serverName", v = AzPgSqlTests.PGSQL_NAME),
},
template = "sunstone/azure/armTemplates/posgresql.json", group = AzPgSqlTests.groupName)
public class AzPgSqlTests {
static final String groupName = "AzPgSqlTests-" + deployGroup;
public static final String PGSQL_NAME = "DSAzureTest-pgsql";
public static final String PGSQL_NAME = "ds-azure-test-pgsql-${ts.test.run}";
public static final String PGSQL_USER = "user";
public static final String PGSQL_PASSWORD = "1234567890Ab";

Expand Down
111 changes: 88 additions & 23 deletions azure/src/test/resources/sunstone/azure/armTemplates/posgresql.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,119 @@
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"username": {
"administratorLogin": {
"type": "string"
},
"password": {
"administratorLoginPassword": {
"type": "securestring"
},
"serverName": {
"type": "string"
},

"version": {
"type": "string",
"defaultValue": "9.6"
"defaultValue": "15"
},
"tags": {
"type": "object",
"defaultValue": {}
},
"firewallRules": {
"type": "object",
"defaultValue": {
"rules": [
{
"name": "AllowAllAzureServicesAndResourcesWithinAzureIps_2024-1-5_9-41-31",
"endIPAddress": "0.0.0.0",
"startIPAddress": "0.0.0.0"
},
{
"name": "AllowAll",
"startIPAddress": "0.0.0.0",
"endIPAddress": "255.255.255.255"
}
]
}
},
"guid": {
"type": "string",
"defaultValue": "[newGuid()]"
}
},
"variables": {
"firewallRules": "[parameters('firewallRules').rules]"
},
"resources": [
{
"apiVersion": "2017-12-01",
"kind": "",
"apiVersion": "2022-12-01",
"location": "[resourceGroup().location]",
"name": "[parameters('serverName')]",
"identity": "[json('null')]",
"properties": {
"createMode": "Default",
"version": "[parameters('version')]",
"sslEnforcement": "Disabled",
"minimalTlsVersion": "TLSEnforcementDisabled",
"infrastructureEncryption": "Disabled",
"publicNetworkAccess": "Enabled",
"administratorLogin": "[parameters('username')]",
"administratorLoginPassword": "[parameters('password')]",
"storageProfile": {
"storageMB": 5120,
"administratorLogin": "[parameters('administratorLogin')]",
"administratorLoginPassword": "[parameters('administratorLoginPassword')]",
"Network": "[json('null')]",
"availabilityZone": "",
"Storage": {
"StorageSizeGB": "32",
"Type": "[json('null')]",
"Autogrow": "Disabled",
"tier": "json('null')",
"Iops": "[json('null')]",
"Throughput": "[json('null')]"
},
"Backup": {
"backupRetentionDays": 7,
"geoRedundantBackup": "Disabled",
"storageAutoGrow": "Disabled"
}
"geoRedundantBackup": "Disabled"
},
"highAvailability": {
"mode": "Disabled",
"standbyAvailabilityZone": ""
},
"dataencryption": "[json('null')]",
"authConfig": "[json('null')]"
},
"sku": {
"name": "B_Gen5_1",
"tier": "Basic",
"family": "Gen5",
"capacity": 1
"name": "Standard_D4s_v3",
"tier": "GeneralPurpose"
},
"tags": "[parameters('tags')]",
"type": "Microsoft.DBforPostgreSQL/servers"
"type": "Microsoft.DBforPostgreSQL/flexibleServers"
},
{
"condition": "[greater(length(variables('firewallRules')), 0)]",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2019-08-01",
"name": "[concat('firewallRules-', parameters('guid'), '-', copyIndex())]",
"copy": {
"count": "[if(greater(length(variables('firewallRules')), 0), length(variables('firewallRules')), 1)]",
"mode": "Serial",
"name": "firewallRulesIterator"
},
"dependsOn": [
"[concat('Microsoft.DBforPostgreSQL/flexibleServers/', parameters('serverName'))]"
],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.DBforPostgreSQL/flexibleServers/firewallRules",
"name": "[concat(parameters('serverName'),'/',variables('firewallRules')[copyIndex()].name)]",
"apiVersion": "2022-12-01",
"properties": {
"StartIpAddress": "[variables('firewallRules')[copyIndex()].startIPAddress]",
"EndIpAddress": "[variables('firewallRules')[copyIndex()].endIPAddress]"
}
}
]
}
}
}
],
"variables": {}
]
}
29 changes: 15 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@

<!-- Azure SDK dependencies & other due to dependencyManagement issues with Azure SDK-->
<!-- Based on https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/resourcemanager#include-the-package-->
<version.azure-resourcemanager>2.20.0</version.azure-resourcemanager>
<version.com.azure.azure-identity>1.6.1</version.com.azure.azure-identity>
<version.com.azure.azure-core-http-netty>1.12.6</version.com.azure.azure-core-http-netty>
<version.azure-resourcemanager-postgresql>1.0.2</version.azure-resourcemanager-postgresql>
<version.azure-resourcemanager>2.34.0</version.azure-resourcemanager>
<version.azure-sdk-bom>1.2.19</version.azure-sdk-bom>
<version.azure-resourcemanager-postgresqlflexibleserver>1.0.0</version.azure-resourcemanager-postgresqlflexibleserver>

<!-- Azure SDK uses okhttp3 which is also brought by Sunstone core...we need to find suitable version... -->
<version.com.squareup.okhttp3>4.10.0</version.com.squareup.okhttp3>
Expand Down Expand Up @@ -320,26 +319,28 @@
</dependency>

<!-- Azure-->
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager</artifactId>
<version>${version.azure-resourcemanager}</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>${version.com.azure.azure-identity}</version>
<artifactId>azure-sdk-bom</artifactId>
<version>${version.azure-sdk-bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-http-netty</artifactId>
<version>${version.com.azure.azure-core-http-netty}</version>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager</artifactId>
<version>${version.azure-resourcemanager}</version>
</dependency>
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-postgresql</artifactId>
<version>${version.azure-resourcemanager-postgresql}</version>
</dependency>
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-postgresqlflexibleserver</artifactId>
<version>${version.azure-resourcemanager-postgresqlflexibleserver}</version>
</dependency>

<!-- logging -->
<dependency>
Expand Down

0 comments on commit daaefbb

Please sign in to comment.