2 * Copyright (c) 2015 Huawei Technologies and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.groupbasedpolicy.renderer.faas;
10 import java.util.concurrent.ScheduledExecutorService;
12 import com.google.common.annotations.VisibleForTesting;
13 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
14 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.faas.logical.faas.common.rev151013.Uuid;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.Tenant;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 public class FaasTenantManagerListener implements DataChangeListener {
25 private static final Logger LOG = LoggerFactory.getLogger(FaasTenantManagerListener.class);
26 private final ScheduledExecutorService executor;
27 private final TenantId gbpTenantId;
28 private final Uuid faasTenantId;
29 private final FaasPolicyManager policyManager;
31 public FaasTenantManagerListener(FaasPolicyManager policyManager, TenantId gbpTenantId, Uuid faasTenantId,
32 ScheduledExecutorService executor) {
33 this.executor = executor;
34 this.faasTenantId = faasTenantId;
35 this.gbpTenantId = gbpTenantId;
36 this.policyManager = policyManager;
40 public void onDataChanged(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
41 executor.execute(new Runnable() {
50 void executeEvent(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
52 for (InstanceIdentifier<?> iid : change.getRemovedPaths()) {
53 DataObject old = change.getOriginalData().get(iid);
57 if (old instanceof Tenant) {
58 Tenant tenant = (Tenant) old;
59 if (tenant.getId().equals(gbpTenantId)) {
60 LOG.info("Removed gbp Tenant {} -- faas Tenant {}", gbpTenantId.getValue(),
61 faasTenantId.getValue());
62 this.policyManager.removeTenantLogicalNetwork(gbpTenantId, faasTenantId);