2 * Copyright (c) 2013 Cisco Systems, Inc. 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.bgpcep.pcep.topology.provider;
10 import com.google.common.base.Function;
11 import com.google.common.collect.Lists;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import java.util.Collections;
15 import java.util.List;
16 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObjectBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.Errors;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcerr.message.pcerr.message.ErrorsBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.FailureType;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.OperationResult;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.operation.result.Error;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.operation.result.ErrorBuilder;
24 import org.opendaylight.yangtools.yang.binding.DataContainer;
29 final class OperationResults implements OperationResult {
30 static final OperationResults NOACK = new OperationResults(FailureType.NoAck);
31 static final OperationResults SUCCESS = new OperationResults((FailureType)null);
32 static final OperationResults UNSENT = new OperationResults(FailureType.Unsent);
34 private static final Function<Errors, Error> CONVERT_ERRORS = new Function<Errors, Error>() {
36 public Error apply(final Errors input) {
37 return new ErrorBuilder(input).build();
41 private final FailureType failure;
42 private final List<Error> error;
44 private OperationResults(final FailureType failure) {
45 this.failure = failure;
49 private OperationResults(final FailureType failure, final List<Error> error) {
50 this.failure = failure;
54 ListenableFuture<OperationResult> future() {
55 return Futures.<OperationResult> immediateFuture(this);
58 public static OperationResults createFailed(final List<Errors> errors) {
59 final List<Errors> e = errors != null ? errors : Collections.<Errors>emptyList();
60 return new OperationResults(FailureType.Failed, Lists.transform(e, CONVERT_ERRORS));
63 public static OperationResults createUnsent(final PCEPErrors error) {
64 final List<Errors> e = error != null ? Collections.singletonList(getErrorFor(error)) : Collections.<Errors>emptyList();
65 return new OperationResults(FailureType.Unsent, Lists.transform(e, CONVERT_ERRORS));
68 private static Errors getErrorFor(final PCEPErrors error) {
69 final ErrorsBuilder builder = new ErrorsBuilder();
70 builder.setErrorObject(new ErrorObjectBuilder().setType(error.getErrorType()).setValue(error.getErrorValue()).build());
71 return builder.build();
75 public FailureType getFailure() {
80 public List<Error> getError() {
85 public Class<? extends DataContainer> getImplementedInterface() {
86 return OperationResult.class;