Commit cbcce545 authored by Gitlab Runner's avatar Gitlab Runner
Browse files
parents 32213d23 3e96253d
......@@ -49,8 +49,9 @@ import lombok.extern.slf4j.Slf4j;
public class DatastoreAccess implements IDatastoreAccess {
private static final String SUBSCRIBER_DB_NAME = "subscription";
@Autowired
private PushSubscription pushSubscription;
/*
* @Autowired private PushSubscription pushSubscription;
*/
@Autowired
private DatastoreMultiTenantAccess dataStoreTenants;
@Autowired
......
/*
* Copyright 2017-2020, Schlumberger
*
* 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.register.provider.ibm.subscriber;
import com.google.api.gax.rpc.NotFoundException;
import com.google.cloud.pubsub.v1.SubscriptionAdminClient;
import com.google.protobuf.Duration;
import com.google.pubsub.v1.ExpirationPolicy;
import com.google.pubsub.v1.ProjectSubscriptionName;
import com.google.pubsub.v1.ProjectTopicName;
import com.google.pubsub.v1.PushConfig;
import java.io.IOException;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.register.utils.AppServiceConfig;
import org.opengroup.osdu.register.subscriber.model.Subscription;
import org.opengroup.osdu.register.utils.AppServiceConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;
@Component
public class PushSubscription {
private static final int ackDeadlineSeconds = 60;
private static final int messageRetentionSeconds = 432000;
private static final int subscriptionExpirationSeconds = 31540000;
@Autowired
private AppServiceConfig serviceConfig;
......@@ -43,46 +18,14 @@ public class PushSubscription {
public Subscription create(Subscription subscription, TenantInfo tenant,
String masterGcpId, String serviceIdentityEmail)
throws IOException {
createPushSubscription(
tenant.getProjectId(),
masterGcpId,
subscription.getTopic(),
subscription.getNotificationId(),
serviceConfig.getRecordsChangePubsubEndpoint(),
serviceIdentityEmail);
return subscription;
return null;
}
public void delete(String servicesProjectId, String subscriptionId) throws IOException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
try {
ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of(servicesProjectId, subscriptionId);
subscriptionAdminClient.deleteSubscription(subscriptionName);
} catch (NotFoundException e) {
//silently catch
}
}
}
private com.google.pubsub.v1.Subscription createPushSubscription(String tenantProjectId, String servicesProjectId, String topicId,
String subscriptionId, String url, String serviceIdentityEmail) throws IOException {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
ProjectTopicName topicName = ProjectTopicName.of(tenantProjectId, topicId);
ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of(servicesProjectId, subscriptionId);
PushConfig config = PushConfig.newBuilder()
.setPushEndpoint(url)
.setOidcToken(PushConfig.OidcToken.newBuilder().setServiceAccountEmail(serviceIdentityEmail).build())
.build();
return subscriptionAdminClient.createSubscription(com.google.pubsub.v1.Subscription.newBuilder()
.setName(subscriptionName.toString())
.setTopic(topicName.toString())
.setPushConfig(config)
.setExpirationPolicy(ExpirationPolicy.newBuilder().setTtl(
Duration.newBuilder().setSeconds(subscriptionExpirationSeconds).build()).build())
.setMessageRetentionDuration(Duration.newBuilder().setSeconds(messageRetentionSeconds).build())
.setAckDeadlineSeconds(ackDeadlineSeconds)
.build());
}
}
}
Supports Markdown
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