Skip to content

Commit

Permalink
Saving work on proper Azure data types for Magpie Persistence and des…
Browse files Browse the repository at this point in the history
…erialization
  • Loading branch information
kickroot committed Mar 6, 2024
1 parent 938b1d7 commit eba8eab
Show file tree
Hide file tree
Showing 8 changed files with 444 additions and 4 deletions.
4 changes: 4 additions & 0 deletions magpie-azure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
<groupId>io.openraven.magpie</groupId>
<artifactId>magpie-api</artifactId>
</dependency>
<dependency>
<groupId>io.openraven.magpie</groupId>
<artifactId>magpie-data</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import io.openraven.magpie.api.Emitter;
import io.openraven.magpie.api.MagpieAzureResource;
import io.openraven.magpie.api.Session;
import io.openraven.magpie.data.azure.sql.SQLDatabase;
import io.openraven.magpie.data.azure.sql.SQLServer;
import io.openraven.magpie.plugins.azure.discovery.AzureUtils;
import io.openraven.magpie.plugins.azure.discovery.VersionedMagpieEnvelopeProvider;
import org.slf4j.Logger;
Expand Down Expand Up @@ -66,7 +68,8 @@ public void discover(ObjectMapper mapper, Session session, Emitter emitter, Logg

private void discoverServers(ObjectMapper mapper, Session session, Emitter emitter, Logger logger, Subscription subscription, AzureResourceManager azrm, AzureProfile profile) {

final var resourceType = fullService() + ":server";
final var resourceType = SQLServer.RESOURCE_TYPE;

azrm.sqlServers().list().forEach(sql -> {
try {
final var data = new MagpieAzureResource.MagpieAzureResourceBuilder(mapper, sql.id())
Expand All @@ -93,7 +96,9 @@ private void discoverServers(ObjectMapper mapper, Session session, Emitter emitt
}

private void discoverDatabases(ObjectMapper mapper, Session session, Emitter emitter, Logger logger, Subscription subscription, AzureResourceManager azrm, SqlServer server) {
final var resourceType = fullService() + ":database";

final var resourceType = SQLDatabase.RESOURCE_TYPE;

server.databases().list().forEach(db -> {
try {
final var data = new MagpieAzureResource.MagpieAzureResourceBuilder(mapper, db.id())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import io.openraven.magpie.api.Emitter;
import io.openraven.magpie.api.MagpieAzureResource;
import io.openraven.magpie.api.Session;
import io.openraven.magpie.data.azure.storage.StorageAccount;
import io.openraven.magpie.data.azure.storage.StorageBlobContainer;
import io.openraven.magpie.plugins.azure.discovery.AzureUtils;
import io.openraven.magpie.plugins.azure.discovery.VersionedMagpieEnvelopeProvider;
import org.apache.commons.lang3.tuple.Triple;
Expand Down Expand Up @@ -79,7 +81,8 @@ public void discover(ObjectMapper mapper, Session session, Emitter emitter, Logg

private void discoverStorageContainers(ObjectMapper mapper, Session session, Emitter emitter, Logger logger, String subscriptionID, AzureResourceManager azrm, AzureProfile profile, List<Triple<String, String, String>> triples) {

final var resourceType = fullService() + ":storageBlobContainer";
final var resourceType = StorageBlobContainer.RESOURCE_TYPE;

final Subscription currentSubscription = azrm.getCurrentSubscription();

triples.forEach(singleTuple ->
Expand Down Expand Up @@ -116,7 +119,9 @@ private List<Triple<String, String, String>> discoverStorageAccounts(ObjectMappe

azrm.storageAccounts().list().forEach(sa -> {
try {
final var resourceType = fullService() + ":storageAccount";

final var resourceType = StorageAccount.RESOURCE_TYPE;

final Subscription currentSubscription = azrm.getCurrentSubscription();
final var data = new MagpieAzureResource.MagpieAzureResourceBuilder(mapper, sa.id())
.withRegion(sa.regionName())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
/*-
* #%L
* Magpie API
* %%
* Copyright (C) 2021 Open Raven Inc
* %%
* Licensed 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.
* #L%
*/
/*
* Copyright 2021 Open Raven Inc
*
* Licensed 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 io.openraven.magpie.data.azure;

import com.fasterxml.jackson.databind.JsonNode;
import io.openraven.magpie.data.Resource;
import io.openraven.magpie.data.utils.JsonConverter;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import java.time.Instant;

@Access(AccessType.FIELD)
@MappedSuperclass
public class AzureResource extends Resource {
@Id
@Column(name = "documentid", columnDefinition = "TEXT",
nullable = false, unique = true)
public String documentId;

@Column(name = "resourceid", columnDefinition = "TEXT")
public String resourceId;

@Column(name = "resourcename", columnDefinition = "TEXT")
public String resourceName;

// this needs to be updatable = false due to its use as a discriminator
@Column(name = "resourcetype", columnDefinition = "TEXT", updatable = false)
public String resourceType;

@Column(name = "region", columnDefinition = "TEXT")
public String region;

@Column(name = "subscriptionId", columnDefinition = "TEXT")
public String subscriptionId;

@Column(name = "creatediso", columnDefinition = "TIMESTAMPTZ")
public Instant createdIso;

@Column(name = "updatediso", columnDefinition = "TIMESTAMPTZ")
public Instant updatedIso;

@Transient
public Long maxSizeInBytes;

@Transient
public Long sizeInBytes;

@Column(name = "configuration", columnDefinition = "JSONB")
@Convert(converter = JsonConverter.class)
public JsonNode configuration;

@Column(name = "supplementaryconfiguration", columnDefinition = "JSONB")
@Convert(converter = JsonConverter.class)
public JsonNode supplementaryConfiguration;

@Column(name = "tags", columnDefinition = "JSONB")
@Convert(converter = JsonConverter.class)
public JsonNode tags;

@Column(name = "discoverymeta", columnDefinition = "JSONB")
@Convert(converter = JsonConverter.class)
public JsonNode discoveryMeta;

public AzureResource() {
}

public String getDocumentId() {
return documentId;
}

public void setDocumentId(String documentId) {
this.documentId = documentId;
}

public String getResourceName() {
return resourceName;
}

public void setResourceName(String resourceName) {
this.resourceName = resourceName;
}

public String getResourceId() {
return resourceId;
}

public void setResourceId(String resourceId) {
this.resourceId = resourceId;
}

public String getResourceType() {
return resourceType;
}

public void setResourceType(String resourceType) {
this.resourceType = resourceType;
}

public String getRegion() {
return region;
}

public void setRegion(String region) {
this.region = region;
}

public String getSubscriptionId() {
return subscriptionId;
}

public void setSubscriptionId(String subscriptionId) {
this.subscriptionId = subscriptionId;
}

public Instant getCreatedIso() {
return createdIso;
}

public void setCreatedIso(Instant createdIso) {
this.createdIso = createdIso;
}

public Instant getUpdatedIso() {
return updatedIso;
}

public void setUpdatedIso(Instant updatedIso) {
this.updatedIso = updatedIso;
}

public Long getMaxSizeInBytes() {
return maxSizeInBytes;
}

public void setMaxSizeInBytes(Long maxSizeInBytes) {
this.maxSizeInBytes = maxSizeInBytes;
}

public Long getSizeInBytes() {
return sizeInBytes;
}

public void setSizeInBytes(Long sizeInBytes) {
this.sizeInBytes = sizeInBytes;
}

public JsonNode getConfiguration() {
return configuration;
}

public void setConfiguration(JsonNode configuration) {
this.configuration = configuration;
}

public JsonNode getSupplementaryConfiguration() {
return supplementaryConfiguration;
}

public void setSupplementaryConfiguration(JsonNode supplementaryConfiguration) {
this.supplementaryConfiguration = supplementaryConfiguration;
}

public JsonNode getTags() {
return tags;
}

public void setTags(JsonNode tags) {
this.tags = tags;
}

public JsonNode getDiscoveryMeta() {
return discoveryMeta;
}

public void setDiscoveryMeta(JsonNode discoveryMeta) {
this.discoveryMeta = discoveryMeta;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*-
* #%L
* Magpie API
* %%
* Copyright (C) 2021 Open Raven Inc
* %%
* Licensed 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.
* #L%
*/
/*
* Copyright 2021 Open Raven Inc
*
* Licensed 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 io.openraven.magpie.data.azure.sql;

import io.openraven.magpie.data.azure.AzureResource;

@javax.persistence.Entity
@javax.persistence.Inheritance(strategy = javax.persistence.InheritanceType.TABLE_PER_CLASS)
@javax.persistence.Table(name = SQLDatabase.TABLE_NAME)
public class SQLDatabase extends AzureResource {

protected static final String TABLE_NAME = "azuresqldatabase";
public static final String RESOURCE_TYPE = "Azure::SQL::Database";

@SuppressWarnings("unused")
public SQLDatabase() {
this.resourceType = RESOURCE_TYPE;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*-
* #%L
* Magpie API
* %%
* Copyright (C) 2021 Open Raven Inc
* %%
* Licensed 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.
* #L%
*/
/*
* Copyright 2021 Open Raven Inc
*
* Licensed 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 io.openraven.magpie.data.azure.sql;

import io.openraven.magpie.data.aws.shared.PayloadUtils;
import io.openraven.magpie.data.azure.AzureResource;
import software.amazon.awssdk.services.rds.model.DBInstance;

@javax.persistence.Entity
@javax.persistence.Inheritance(strategy = javax.persistence.InheritanceType.TABLE_PER_CLASS)
@javax.persistence.Table(name = SQLServer.TABLE_NAME)
public class SQLServer extends AzureResource {

protected static final String TABLE_NAME = "azuresqlserver";
public static final String RESOURCE_TYPE = "Azure::SQL::Server";

@SuppressWarnings("unused")
public SQLServer() {
this.resourceType = RESOURCE_TYPE;
}

}
Loading

0 comments on commit eba8eab

Please sign in to comment.