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.Collection;
11 import java.util.concurrent.Executor;
12 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
13 import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
14 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
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.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 public class FaasTenantManagerListener implements DataTreeChangeListener<Tenant> {
23 private static final Logger LOG = LoggerFactory.getLogger(FaasTenantManagerListener.class);
24 private final Executor executor;
25 private final TenantId gbpTenantId;
26 private final Uuid faasTenantId;
27 private final FaasPolicyManager policyManager;
29 public FaasTenantManagerListener(FaasPolicyManager policyManager, TenantId gbpTenantId, Uuid faasTenantId,
31 this.executor = executor;
32 this.faasTenantId = faasTenantId;
33 this.gbpTenantId = gbpTenantId;
34 this.policyManager = policyManager;
38 public void onDataTreeChanged(final Collection<DataTreeModification<Tenant>> changes) {
39 executor.execute(() -> executeEvent(changes));
42 private void executeEvent(final Collection<DataTreeModification<Tenant>> changes) {
43 for (DataTreeModification<Tenant> change: changes) {
44 DataObjectModification<Tenant> rootNode = change.getRootNode();
45 switch (rootNode.getModificationType()) {
47 final Tenant tenant = rootNode.getDataBefore();
48 if (tenant.getId().equals(gbpTenantId)) {
49 LOG.info("Removed gbp Tenant {} -- faas Tenant {}", gbpTenantId.getValue(),
50 faasTenantId.getValue());
51 this.policyManager.removeTenantLogicalNetwork(gbpTenantId, faasTenantId);