Commit b54c1fcd authored by Komal Makkar's avatar Komal Makkar
Browse files

intermediate change

parent 14548e04
......@@ -18,7 +18,7 @@ import com.azure.identity.DefaultAzureCredential;
import com.azure.storage.blob.BlobContainerClient;
import com.azure.storage.blob.BlobContainerClientBuilder;
import org.opengroup.osdu.azure.cache.BlobContainerClientCache;
import org.opengroup.osdu.azure.partition.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.models.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.PartitionServiceClient;
import org.opengroup.osdu.common.Validators;
import org.springframework.beans.factory.annotation.Autowired;
......
......@@ -18,7 +18,7 @@ import com.azure.identity.DefaultAzureCredential;
import com.azure.storage.blob.BlobServiceClient;
import com.azure.storage.blob.BlobServiceClientBuilder;
import org.opengroup.osdu.azure.cache.BlobServiceClientCache;
import org.opengroup.osdu.azure.partition.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.models.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.PartitionServiceClient;
import org.opengroup.osdu.common.Validators;
......
......@@ -7,7 +7,7 @@ import com.microsoft.azure.documentdb.DocumentClientException;
import com.microsoft.azure.documentdb.DocumentCollection;
import com.microsoft.azure.documentdb.bulkexecutor.DocumentBulkExecutor;
import org.opengroup.osdu.azure.cache.CosmosBulkExecutorCache;
import org.opengroup.osdu.azure.partition.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.models.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.PartitionServiceClient;
import org.opengroup.osdu.common.Validators;
import org.opengroup.osdu.core.common.model.http.AppException;
......
......@@ -3,7 +3,7 @@ package org.opengroup.osdu.azure.cosmosdb;
import com.azure.cosmos.CosmosClient;
import com.azure.cosmos.CosmosClientBuilder;
import org.opengroup.osdu.azure.cache.CosmosClientCache;
import org.opengroup.osdu.azure.partition.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.models.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.PartitionServiceClient;
import org.opengroup.osdu.common.Validators;
import org.springframework.beans.factory.annotation.Autowired;
......
package org.opengroup.osdu.azure.cryptography;
import org.opengroup.osdu.azure.cache.CryptographyClientCache;
import org.opengroup.osdu.azure.partition.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.models.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.PartitionServiceClient;
import org.opengroup.osdu.common.Validators;
import org.springframework.beans.factory.annotation.Autowired;
......
......@@ -18,7 +18,9 @@ import com.microsoft.azure.eventgrid.EventGridClient;
import com.microsoft.azure.eventgrid.TopicCredentials;
import com.microsoft.azure.eventgrid.implementation.EventGridClientImpl;
import org.opengroup.osdu.azure.cache.EventGridTopicClientCache;
import org.opengroup.osdu.azure.partition.EventGridTopicPartitionInfoAzure;
import org.opengroup.osdu.azure.partition.IAzureResourceConfigProvider;
import org.opengroup.osdu.azure.partition.models.EventGridPartitionConfig;
import org.opengroup.osdu.azure.partition.models.EventGridTopicPartitionInfoAzure;
import org.opengroup.osdu.azure.partition.PartitionServiceEventGridClient;
import org.opengroup.osdu.common.Validators;
import org.opengroup.osdu.core.common.partition.PartitionException;
......@@ -40,6 +42,9 @@ public class EventGridTopicClientFactoryImpl implements IEventGridTopicClientFac
@Autowired
private EventGridTopicClientCache clientCache;
@Autowired
private EventGridPartitionConfig eventGridPartitionConfig;
/**
*
* @param dataPartitionId Data partition id
......@@ -58,7 +63,7 @@ public class EventGridTopicClientFactoryImpl implements IEventGridTopicClientFac
}
EventGridTopicPartitionInfoAzure eventGridTopicPartitionInfoAzure =
this.partitionService.getEventGridTopicInPartition(dataPartitionId, topicName);
eventGridPartitionConfig.getTopicsRegistered().get(topicName);
TopicCredentials topicCredentials =
new TopicCredentials(eventGridTopicPartitionInfoAzure.getTopicAccessKey());
......
......@@ -18,7 +18,7 @@ import com.microsoft.azure.eventgrid.EventGridClient;
import com.microsoft.azure.eventgrid.models.EventGridEvent;
import lombok.SneakyThrows;
import org.opengroup.osdu.azure.cosmosdb.CosmosStoreBulkOperations;
import org.opengroup.osdu.azure.partition.EventGridTopicPartitionInfoAzure;
import org.opengroup.osdu.azure.partition.models.EventGridTopicPartitionInfoAzure;
import org.opengroup.osdu.azure.partition.PartitionServiceEventGridClient;
import org.opengroup.osdu.core.common.logging.ILogger;
import org.opengroup.osdu.core.common.model.http.AppException;
......
package org.opengroup.osdu.azure.eventgridmanager;
import org.opengroup.osdu.azure.cache.EventGridManagerCache;
import org.opengroup.osdu.azure.partition.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.models.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.PartitionServiceClient;
import org.opengroup.osdu.azure.util.AzureTokenCredentialsService;
import org.opengroup.osdu.common.Validators;
......
......@@ -14,7 +14,7 @@
package org.opengroup.osdu.azure.multitenancy;
import org.opengroup.osdu.azure.partition.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.models.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.PartitionServiceClient;
import org.opengroup.osdu.core.common.cache.ICache;
import org.opengroup.osdu.core.common.logging.ILogger;
......
// Copyright © Microsoft Corporation
//
// 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 org.opengroup.osdu.azure.partition;
import org.opengroup.osdu.azure.util.AzureServicePrincipleTokenService;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.partition.IPartitionFactory;
import org.opengroup.osdu.core.common.partition.IPartitionProvider;
import org.opengroup.osdu.core.common.partition.PartitionException;
import org.opengroup.osdu.core.common.partition.PartitionInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class PartitionInfoProvider {
}
......@@ -4,6 +4,7 @@ import com.azure.security.keyvault.secrets.SecretClient;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.azure.partition.models.PartitionInfoAzure;
import org.opengroup.osdu.azure.util.AzureServicePrincipleTokenService;
import org.opengroup.osdu.common.Validators;
import org.opengroup.osdu.core.common.model.http.AppException;
......@@ -23,7 +24,7 @@ import java.util.List;
*/
@Service
@Lazy
public class PartitionServiceClient {
public class PartitionServiceClient{
@Autowired
private IPartitionFactory partitionFactory;
......
......@@ -19,6 +19,7 @@ import com.google.gson.Gson;
import com.google.gson.JsonElement;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.azure.KeyVaultFacade;
import org.opengroup.osdu.azure.partition.models.EventGridTopicPartitionInfoAzure;
import org.opengroup.osdu.azure.util.AzureServicePrincipleTokenService;
import org.opengroup.osdu.common.Validators;
import org.opengroup.osdu.core.common.model.http.AppException;
......@@ -43,7 +44,7 @@ import java.util.StringTokenizer;
*/
@Service
@Lazy
public class PartitionServiceEventGridClient {
public class PartitionServiceEventGridClient { //rename
private static final String ACCESS_KEY_REGEX = "^eventgrid-([a-zA-Z0-9]*)topic-accesskey$";
private static final String TOPIC_NAME_REGEX = "^eventgrid-([a-zA-Z0-9]*)topic$";
private static final Logger LOGGER = LoggerFactory.getLogger(PartitionServiceEventGridClient.class.getName());
......@@ -112,7 +113,7 @@ public class PartitionServiceEventGridClient {
* @return PartitionInfo
* @throws PartitionException Exception thrown by {@link IPartitionFactory}
*/
PartitionInfo getPartitionInfo(final String partitionId) throws PartitionException {
PartitionInfo getPartitionInfo(final String partitionId) throws PartitionException { // partitionserviceclient
IPartitionProvider serviceClient = getServiceClient();
return serviceClient.get(partitionId);
}
......
// Copyright © Microsoft Corporation
//
// 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 org.opengroup.osdu.azure.partition.adapters;
import org.opengroup.osdu.azure.partition.models.IAzureResourcePartitionConfig;
import org.opengroup.osdu.azure.util.AzureServicePrincipleTokenService;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.partition.IPartitionFactory;
import org.opengroup.osdu.core.common.partition.IPartitionProvider;
import org.opengroup.osdu.core.common.partition.PartitionException;
import org.opengroup.osdu.core.common.partition.PartitionInfo;
import org.springframework.beans.factory.annotation.Autowired;
public abstract class AzureResourcePartitionConfigAdapter implements IAzureResourcePartitionConfigAdapter {
@Autowired
private DpsHeaders headers;
@Autowired
private AzureServicePrincipleTokenService tokenService;
@Autowired
private IPartitionFactory partitionFactory;
public abstract IAzureResourcePartitionConfig getConfig(String partitionId);
public PartitionInfo getPartitionInfo(String partitionId) throws PartitionException {
IPartitionProvider serviceClient = getServiceClient();
return serviceClient.get(partitionId);
}
/**
* Get Service client for Partition Service.
*
* @return PartitionServiceClient
*/
private IPartitionProvider getServiceClient() {
this.headers.put(DpsHeaders.AUTHORIZATION, "Bearer " + this.tokenService.getAuthorizationToken());
return this.partitionFactory.create(headers);
}
}
// Copyright © Microsoft Corporation
//
// 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 org.opengroup.osdu.azure.partition.adapters;
import com.azure.security.keyvault.secrets.SecretClient;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.azure.KeyVaultFacade;
import org.opengroup.osdu.azure.partition.PartitionServiceEventGridClient;
import org.opengroup.osdu.azure.partition.models.EventGridPartitionConfig;
import org.opengroup.osdu.azure.partition.models.EventGridTopicPartitionInfoAzure;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.partition.PartitionException;
import org.opengroup.osdu.core.common.partition.PartitionInfo;
import org.opengroup.osdu.core.common.partition.Property;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
public class EventGridPartitionConfigAdapter extends AzureResourcePartitionConfigAdapter {
private static final String ACCESS_KEY_REGEX = "^eventgrid-([a-zA-Z0-9]*)topic-accesskey$";
private static final String TOPIC_NAME_REGEX = "^eventgrid-([a-zA-Z0-9]*)topic$";
private static final Logger LOGGER = LoggerFactory.getLogger(PartitionServiceEventGridClient.class.getName());
private final Gson gson = new Gson();
@Autowired
private SecretClient secretClient;
@Override
public EventGridPartitionConfig getConfig(String partitionId) {
Map<String, EventGridTopicPartitionInfoAzure> topics = new HashMap<>();
PartitionInfo partitionInfo;
try {
partitionInfo = getPartitionInfo(partitionId);
Map<String, Property> propertyMap = partitionInfo.getProperties();
for (Map.Entry<String, Property> property : propertyMap.entrySet()) {
if (isEventGridProperty(property)) {
StringTokenizer stringTokenizer = new StringTokenizer(property.getKey(), "-");
if (stringTokenizer.countTokens() == 2) {
addEventGridTopicName(topics, property, stringTokenizer);
} else if (stringTokenizer.countTokens() == 3) {
addEventGridAccessKey(topics, property, stringTokenizer);
} else {
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Invalid EventGrid Partition configuration for the partition " + partitionId, "Please reconfigure the partition service");
}
}
}
} catch (PartitionException e) {
e.printStackTrace();
}
return new EventGridPartitionConfig(topics);
}
/**
* Util to identify if property is for event grid topic.
*
* @param property property
* @return isEventGridProperty
*/
private boolean isEventGridProperty(final Map.Entry<String, Property> property) {
return property.getKey().matches((ACCESS_KEY_REGEX)) || property.getKey().matches((TOPIC_NAME_REGEX));
}
/**
* Populate the map.
*
* @param topics topics
* @param property properties
* @param stringTokenizer tokenizer util
*/
private void addEventGridAccessKey(final Map<String, EventGridTopicPartitionInfoAzure> topics,
final Map.Entry<String, Property> property,
final StringTokenizer stringTokenizer) {
stringTokenizer.nextToken();
String secret = getSecretValue(property);
String key = stringTokenizer.nextToken();
if (topics.containsKey(key)) {
EventGridTopicPartitionInfoAzure topic = topics.get(key);
topic.setTopicAccessKey(secret);
} else {
EventGridTopicPartitionInfoAzure topic = new EventGridTopicPartitionInfoAzure();
topic.setTopicAccessKey(secret);
topics.put(key, topic);
}
}
/**
* Populate the map.
*
* @param topics topics
* @param property properties
* @param stringTokenizer tokenizer util
*/
private void addEventGridTopicName(final Map<String, EventGridTopicPartitionInfoAzure> topics,
final Map.Entry<String, Property> property,
final StringTokenizer stringTokenizer) {
stringTokenizer.nextToken();
String key = stringTokenizer.nextToken();
String secretValue = getSecretValue(property);
if (topics.containsKey(key)) {
EventGridTopicPartitionInfoAzure topic = topics.get(key);
topic.setTopicName(secretValue);
} else {
EventGridTopicPartitionInfoAzure topic = new EventGridTopicPartitionInfoAzure();
topic.setTopicName(secretValue);
topics.put(key, topic);
}
}
/**
* Get the secret value from KeyVault.
*
* @param property property
* @return secret
*/
private String getSecretValue(final Map.Entry<String, Property> property) {
JsonElement jsonElement = gson.toJsonTree(property.getValue());
Property p = gson.fromJson(jsonElement, Property.class);
if (p.isSensitive()) {
return KeyVaultFacade.getSecretWithValidation(this.secretClient, String.valueOf(p.getValue()));
}
return String.valueOf(p.getValue());
}
}
// Copyright © Microsoft Corporation
//
// 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 org.opengroup.osdu.azure.partition.adapters;
import org.opengroup.osdu.azure.partition.models.IAzureResourcePartitionConfig;
import org.opengroup.osdu.azure.util.AzureServicePrincipleTokenService;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.partition.IPartitionFactory;
import org.opengroup.osdu.core.common.partition.IPartitionProvider;
import org.opengroup.osdu.core.common.partition.PartitionException;
import org.opengroup.osdu.core.common.partition.PartitionInfo;
import org.springframework.beans.factory.annotation.Autowired;
public interface IAzureResourcePartitionConfigAdapter {
public abstract IAzureResourcePartitionConfig getConfig(String partitionId);
}
// Copyright © Microsoft Corporation
//
// 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 org.opengroup.osdu.azure.partition.models;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Map;
@AllArgsConstructor
@Getter
public class EventGridPartitionConfig extends IAzureResourcePartitionConfig {
Map<String, EventGridTopicPartitionInfoAzure> topicsRegistered;
}
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.azure.partition;
package org.opengroup.osdu.azure.partition.models;
import lombok.AllArgsConstructor;
import lombok.Builder;
......
// Copyright © Microsoft Corporation
//
// 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 org.opengroup.osdu.azure.partition.models;
public class IAzureResourcePartitionConfig {
}
package org.opengroup.osdu.azure.partition;
package org.opengroup.osdu.azure.partition.models;
import com.azure.security.keyvault.secrets.SecretClient;
import com.google.gson.annotations.SerializedName;
......@@ -16,7 +16,7 @@ import org.opengroup.osdu.core.common.partition.Property;
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class PartitionInfoAzure {
public class PartitionInfoAzure extends IAzureResourcePartitionConfig {
@SerializedName("id")
private Property idConfig;
......
......@@ -5,7 +5,7 @@ import com.microsoft.azure.servicebus.SubscriptionClient;
import com.microsoft.azure.servicebus.primitives.ConnectionStringBuilder;
import com.microsoft.azure.servicebus.primitives.ServiceBusException;
import org.opengroup.osdu.azure.cache.SubscriptionClientCache;
import org.opengroup.osdu.azure.partition.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.models.PartitionInfoAzure;
import org.opengroup.osdu.azure.partition.PartitionServiceClient;
import org.opengroup.osdu.common.Validators;
import org.springframework.beans.factory.annotation.Autowired;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment