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 org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
13 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.faas.logical.faas.common.rev151013.Uuid;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.Tenant;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 public class FaasTenantManagerListener implements DataChangeListener {
24 private static final Logger LOG = LoggerFactory.getLogger(FaasTenantManagerListener.class);
25 private final ScheduledExecutorService executor;
26 private final TenantId gbpTenantId;
27 private final Uuid faasTenantId;
28 private final FaasPolicyManager policyManager;
30 public FaasTenantManagerListener(FaasPolicyManager policyManager, TenantId gbpTenantId, Uuid faasTenantId,
31 ScheduledExecutorService executor) {
32 this.executor = executor;
33 this.faasTenantId = faasTenantId;
34 this.gbpTenantId = gbpTenantId;
35 this.policyManager = policyManager;
39 public void onDataChanged(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
40 executor.execute(new Runnable() {
48 private void executeEvent(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
50 for (InstanceIdentifier<?> iid : change.getRemovedPaths()) {
51 DataObject old = change.getOriginalData().get(iid);
55 if (old instanceof Tenant) {
56 Tenant tenant = (Tenant) old;
57 if (tenant.getId().equals(gbpTenantId)) {
58 LOG.info("Removed gbp Tenant {} -- faas Tenant {}", gbpTenantId.getValue(),
59 faasTenantId.getValue());
60 this.policyManager.removeTenantLogicalNetwork(gbpTenantId, faasTenantId);