/*
* Copyright © 2017 Orange, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.transportpce.stubrenderer;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.TopologyBuilder;
import org.opendaylight.yang.gen.v1.http.org.openroadm.topology.rev161014.topology.AToZ;
import org.opendaylight.yang.gen.v1.http.org.openroadm.topology.rev161014.topology.ZToA;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*Class for Sending
* Renderer requests :
* - Service-implementation-request
* - Service-delete-request.
* @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
*
*/
public class SendingRendererRPCs {
/** Logging. */
private static final Logger LOG = LoggerFactory.getLogger(SendingRendererRPCs.class);
/** define procedure success (or not ). */
private Boolean success;
/** define type of request
* true
pathcomputation
* false
cancelresourcereserve. */
private TopologyBuilder topology;
private List atoz;
private List ztoa;
private String error;
private final ListeningExecutorService executor;
public SendingRendererRPCs(ListeningExecutorService executor) {
success = true;
setTopology(null);
this.executor = executor;
setError("");
}
private void buildAtoZ() {
atoz = new ArrayList();
}
private void buildZtoA() {
ztoa = new ArrayList();
}
public ListenableFuture serviceDelete() {
LOG.info("ServiceDelete request ...");
success = false;
return executor.submit(new Callable() {
@Override
public Boolean call() throws Exception {
Boolean output = true;
LOG.info("Wait for 10s til beginning the Renderer serviceDelete request");
try {
Thread.sleep(10000); //sleep for 10s
} catch (InterruptedException e) {
output = false;
LOG.error(e.toString());
}
buildAtoZ();
buildZtoA();
success = true;
return output;
}
});
}
public ListenableFuture serviceImplementation() {
LOG.info("serviceImplementation request ...");
success = false;
return executor.submit(new Callable() {
@Override
public Boolean call() throws Exception {
Boolean output = true;
LOG.info("Wait for 10s til beginning the Renderer serviceDelete request");
try {
Thread.sleep(10000); //sleep for 10s
} catch (InterruptedException e) {
output = false;
LOG.error(e.toString());
}
buildAtoZ();
buildZtoA();
setTopology(new TopologyBuilder()
.setAToZ(atoz)
.setZToA(ztoa));
output = true;
success = true;
return output;
}
});
}
public Boolean getSuccess() {
return success;
}
public void setSuccess(Boolean success) {
this.success = success;
}
public TopologyBuilder getTopology() {
return topology;
}
public void setTopology(TopologyBuilder topo) {
this.topology = topo;
}
public String getError() {
return error;
}
public void setError(String error) {
this.error = error;
}
}