Expose entity details in MDSAL
[controller.git] / opendaylight / md-sal / eos-dom-akka / src / main / java / org / opendaylight / controller / eos / akka / owner / supervisor / command / GetEntityReply.java
1 /*
2  * Copyright (c) 2021 PANTHEON.tech, s.r.o. 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 package org.opendaylight.controller.eos.akka.owner.supervisor.command;
9
10 import com.google.common.collect.ImmutableSet;
11 import java.io.Serializable;
12 import java.util.Set;
13 import java.util.stream.Collectors;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOutput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.GetEntityOutputBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.entity.owners.norev.NodeName;
19
20 public final class GetEntityReply extends OwnerSupervisorReply implements Serializable {
21     private static final long serialVersionUID = 1L;
22
23     private final ImmutableSet<String> candidates;
24     private final String owner;
25
26     public GetEntityReply(final @Nullable String owner, final @Nullable Set<String> candidates) {
27         this.owner = owner;
28         this.candidates = candidates == null ? ImmutableSet.of() : ImmutableSet.copyOf(candidates);
29     }
30
31     public @NonNull GetEntityOutput toOutput() {
32         final GetEntityOutputBuilder builder = new GetEntityOutputBuilder();
33         if (owner != null) {
34             builder.setOwnerNode(new NodeName(owner));
35         }
36         return builder
37             .setCandidateNodes(candidates.stream().map(NodeName::new).collect(Collectors.toUnmodifiableList()))
38             .build();
39     }
40 }