Integrating FAAS renderer with the faas fabric mapping services. Also,
[groupbasedpolicy.git] / renderers / faas / src / main / java / org / opendaylight / groupbasedpolicy / renderer / faas / FaasRenderer.java
1 /*
2  * Copyright (c) 2015 Huawei Technologies and others. All rights reserved.
3  * 
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
7  */
8
9 package org.opendaylight.groupbasedpolicy.renderer.faas;
10
11 import java.util.concurrent.Executors;
12 import java.util.concurrent.ScheduledExecutorService;
13
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.groupbasedpolicy.api.EpRendererAugmentationRegistry;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * Renderer that converts GBP services to FAAS logical networks, which then maps
21  * to the physical networks..
22  */
23 public class FaasRenderer implements AutoCloseable {
24
25     private static final Logger LOG = LoggerFactory.getLogger(FaasRenderer.class);
26
27     private final ScheduledExecutorService executor;
28     private final FaasEndpointManagerListener endpointListner;
29     private final FaasPolicyManager policyManager;
30     private final FaasEndpointAug faasEndpointAug;
31
32     public FaasRenderer(final DataBroker dataProvider, EpRendererAugmentationRegistry epRendererAugmentationRegistry) {
33         int numCPU = Runtime.getRuntime().availableProcessors();
34         executor = Executors.newScheduledThreadPool(numCPU * 2);
35         policyManager = new FaasPolicyManager(dataProvider, executor);
36         endpointListner = new FaasEndpointManagerListener(policyManager, dataProvider, executor);
37         faasEndpointAug = new FaasEndpointAug(epRendererAugmentationRegistry);
38         LOG.info("FAAS Renderer has Started");
39     }
40
41     @Override
42     public void close() throws Exception {
43         executor.shutdownNow();
44         endpointListner.close();
45         policyManager.close();
46         faasEndpointAug.close();
47     }
48 }