* 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.openflowplugin.impl.device.initialization;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.AsyncFunction;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import java.util.ArrayList;
import java.util.List;
-import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
import org.opendaylight.openflowplugin.impl.util.DeviceStateUtil;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterFeatures;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReply;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
// First process description reply, write data to DS and write consequent data if successful
return Futures.transformAsync(
requestMultipart(MultipartType.OFPMPDESC, deviceContext),
- (AsyncFunction<RpcResult<List<OfHeader>>, Void>) input -> {
+ input -> {
translateAndWriteResult(
MultipartType.OFPMPDESC,
input.getResult(),
multipartWriterProvider, convertorExecutor));
return Futures.transform(
- (switchFeaturesMandatory ? Futures.allAsList(futures) : Futures.successfulAsList(futures)),
+ switchFeaturesMandatory ? Futures.allAsList(futures) : Futures.successfulAsList(futures),
new Function<List<RpcResult<List<OfHeader>>>, Void>() {
- @Nullable
@Override
- public Void apply(@Nullable final List<RpcResult<List<OfHeader>>> input) {
+ public Void apply(final List<RpcResult<List<OfHeader>>> input) {
LOG.info("Static node {} successfully finished collecting",
deviceContext.getDeviceInfo());
return null;
}
- });
+ }, MoreExecutors.directExecutor());
}, MoreExecutors.directExecutor());
}
Futures.addCallback(future, new FutureCallback<RpcResult<List<OfHeader>>>() {
@Override
public void onSuccess(final RpcResult<List<OfHeader>> result) {
- if (Objects.nonNull(result.getResult())) {
+ if (result.getResult() != null) {
LOG.info("Static node {} info: {} collected", deviceContext.getDeviceInfo(), type);
translateAndWriteResult(
type,
result.getErrors().forEach(rpcError -> {
LOG.warn("Failed to retrieve static node {} info: {}", type, rpcError.getMessage());
- if (LOG.isTraceEnabled() && Objects.nonNull(rpcError.getCause())) {
+ if (LOG.isTraceEnabled() && rpcError.getCause() != null) {
LOG.trace("Detailed error:", rpcError.getCause());
}
});
}
@Override
- public void onFailure(@Nonnull final Throwable throwable) {
+ public void onFailure(final Throwable throwable) {
LOG.warn("Request of type {} for static info of node {} failed.",
type, deviceContext.getDeviceInfo());
}
final DeviceContext deviceContext,
@Nullable final MultipartWriterProvider multipartWriterProvider,
@Nullable final ConvertorExecutor convertorExecutor) {
- if (Objects.nonNull(result)) {
+ if (result != null) {
try {
result.forEach(reply -> {
// First, translate collected data to proper openflowplugin representation
new SingleLayerMultipartCollectorService(deviceContext, deviceContext);
return Futures.transform(service.handleServiceCall(multipartType),
- new Function<RpcResult<List<MultipartReply>>, RpcResult<List<OfHeader>>>() {
- @Nonnull
- @Override
- public RpcResult<List<OfHeader>> apply(final RpcResult<List<MultipartReply>> input) {
- if (Objects.isNull(input.getResult()) && input.isSuccessful()) {
- final List<OfHeader> temp = null;
- return RpcResultBuilder.success(temp).build();
- }
+ input -> {
+ if (input.getResult() == null && input.isSuccessful()) {
+ return RpcResultBuilder.<List<OfHeader>>success(null).build();
+ }
- return input.isSuccessful()
- ? RpcResultBuilder.success(input
+ return input.isSuccessful()
+ ? RpcResultBuilder.success(input
.getResult()
.stream()
.map(OfHeader.class::cast)
.collect(Collectors.toList()))
.build()
- : RpcResultBuilder.<List<OfHeader>>failed()
+ : RpcResultBuilder.<List<OfHeader>>failed()
.withRpcErrors(input.getErrors())
.build();
- }
- });
+ }, MoreExecutors.directExecutor());
}
final MultiLayerMultipartCollectorService service =
new MultiLayerMultipartCollectorService(deviceContext, deviceContext);
- return Futures.transform(service.handleServiceCall(multipartType), new Function<RpcResult<List<org
- .opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply>>,
- RpcResult<List<OfHeader>>>() {
- @Nonnull
- @Override
- public RpcResult<List<OfHeader>> apply(final RpcResult<List<org.opendaylight.yang.gen.v1.urn.opendaylight
- .openflow.protocol.rev130731.MultipartReply>> input) {
- if (Objects.isNull(input.getResult()) && input.isSuccessful()) {
- final List<OfHeader> temp = null;
- return RpcResultBuilder.success(temp).build();
- }
-
- return input.isSuccessful()
- ? RpcResultBuilder.success(input
- .getResult()
- .stream()
- .map(OfHeader.class::cast)
- .collect(Collectors.toList()))
- .build()
- : RpcResultBuilder.<List<OfHeader>>failed()
- .withRpcErrors(input.getErrors())
- .build();
+ return Futures.transform(service.handleServiceCall(multipartType), input -> {
+ if (input.getResult() == null && input.isSuccessful()) {
+ return RpcResultBuilder.<List<OfHeader>>success(null).build();
}
- });
- }
+ return input.isSuccessful() ? RpcResultBuilder
+ .success(input.getResult().stream().map(OfHeader.class::cast).collect(Collectors.toList())).build()
+ : RpcResultBuilder.<List<OfHeader>>failed().withRpcErrors(input.getErrors()).build();
+ }, MoreExecutors.directExecutor());
+ }
}