Simon Hunt
Committed by Gerrit Code Review

ONOS-4971: Synthetic Link Data -- WIP

- adding CLI commands for dumping Model Cache contents.

Change-Id: I28dfe179835de6cd0c5356faf87af46a239eb772
......@@ -261,6 +261,15 @@ public class UiTopology extends UiElement {
}
/**
* Returns all links in the model.
*
* @return all links
*/
public Set<UiLink> allLinks() {
return new HashSet<>(linkLookup.values());
}
/**
* Returns the link with the specified identifier, or null if no such
* link exists.
*
......@@ -302,6 +311,15 @@ public class UiTopology extends UiElement {
}
/**
* Returns all hosts in the model.
*
* @return all hosts
*/
public Set<UiHost> allHosts() {
return new HashSet<>(hostLookup.values());
}
/**
* Returns the host with the specified identifier, or null if no such
* host exists.
*
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ui.impl.topo.cli;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.ui.model.topo.UiElement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
/**
* Base class for model cache CLI commands.
*/
abstract class AbstractElementCommand extends AbstractShellCommand {
/**
* Built in comparator for elements.
*/
private static final Comparator<UiElement> ELEMENT_COMPARATOR =
(o1, o2) -> o1.idAsString().compareTo(o2.idAsString());
/**
* Returns the given elements in a list, sorted by string representation
* of the identifiers.
*
* @param elements the elements to sort
* @return the sorted elements
*/
protected List<UiElement> sorted(Set<? extends UiElement> elements) {
List<UiElement> list = new ArrayList<>(elements);
Collections.sort(list, ELEMENT_COMPARATOR);
return list;
}
}
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ui.impl.topo.cli;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel;
/**
* CLI command to list the UiDevices stored in the ModelCache.
*/
@Command(scope = "onos", name = "ui-cache-devices",
description = "Lists UiDevices in the Model Cache")
public class ListDevices extends AbstractElementCommand {
@Override
protected void execute() {
UiSharedTopologyModel model = get(UiSharedTopologyModel.class);
sorted(model.getDevices()).forEach(d -> print("%s", d));
}
}
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ui.impl.topo.cli;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel;
/**
* CLI command to list the UiH0osts stored in the ModelCache.
*/
@Command(scope = "onos", name = "ui-cache-hosts",
description = "Lists UiHosts in the Model Cache")
public class ListHosts extends AbstractElementCommand {
@Override
protected void execute() {
UiSharedTopologyModel model = get(UiSharedTopologyModel.class);
sorted(model.getHosts()).forEach(h -> print("%s", h));
}
}
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ui.impl.topo.cli;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel;
/**
* CLI command to list the UiLinks stored in the ModelCache.
*/
@Command(scope = "onos", name = "ui-cache-links",
description = "Lists UiLinks in the Model Cache")
public class ListLinks extends AbstractElementCommand {
@Override
protected void execute() {
UiSharedTopologyModel model = get(UiSharedTopologyModel.class);
sorted(model.getLinks()).forEach(l -> print("%s", l));
}
}
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ui.impl.topo.cli;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel;
/**
* CLI command to list the UiClusterMembers stored in the ModelCache.
*/
@Command(scope = "onos", name = "ui-cache-members",
description = "Lists UiClusterMembers in the Model Cache")
public class ListMembers extends AbstractElementCommand {
@Override
protected void execute() {
UiSharedTopologyModel model = get(UiSharedTopologyModel.class);
// note: getClusterMembers() returns an already sorted list...
model.getClusterMembers().forEach(m -> print("%s", m));
}
}
......@@ -17,7 +17,6 @@
package org.onosproject.ui.impl.topo.cli;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel;
/**
......@@ -25,11 +24,11 @@ import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel;
*/
@Command(scope = "onos", name = "ui-cache-regions",
description = "Lists UiRegions in the Model Cache")
public class ListRegions extends AbstractShellCommand {
public class ListRegions extends AbstractElementCommand {
@Override
protected void execute() {
UiSharedTopologyModel model = get(UiSharedTopologyModel.class);
model.getRegions().forEach(r -> print("%s", r));
sorted(model.getRegions()).forEach(r -> print("%s", r));
}
}
......
......@@ -298,6 +298,10 @@ class ModelCache {
}
}
Set<UiDevice> getAllDevices() {
return uiTopology.allDevices();
}
// === LINKS
......@@ -357,6 +361,9 @@ class ModelCache {
}
}
Set<UiLink> getAllLinks() {
return uiTopology.allLinks();
}
// === HOSTS
......@@ -460,6 +467,10 @@ class ModelCache {
}
}
Set<UiHost> getAllHosts() {
return uiTopology.allHosts();
}
/**
* Refreshes the internal state.
......
......@@ -63,6 +63,9 @@ import org.onosproject.net.topology.TopologyService;
import org.onosproject.ui.impl.topo.UiTopoSession;
import org.onosproject.ui.model.ServiceBundle;
import org.onosproject.ui.model.topo.UiClusterMember;
import org.onosproject.ui.model.topo.UiDevice;
import org.onosproject.ui.model.topo.UiHost;
import org.onosproject.ui.model.topo.UiLink;
import org.onosproject.ui.model.topo.UiRegion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -200,7 +203,14 @@ public final class UiSharedTopologyModel
// Methods for topo session (or CLI) to use to get information from us
/**
* Returns the list of cluster members stored in our model cache.
* Refreshes the cache's internal state.
*/
public void refresh() {
cache.refresh();
}
/**
* Returns the list of cluster members stored in the model cache.
*
* @return list of cluster members
*/
......@@ -209,7 +219,7 @@ public final class UiSharedTopologyModel
}
/**
* Returns the set of regions stored in our model cache.
* Returns the set of regions stored in the model cache.
*
* @return set of regions
*/
......@@ -237,10 +247,30 @@ public final class UiSharedTopologyModel
}
/**
* Refreshes the cache's internal state.
* Returns the set of devices stored in the model cache.
*
* @return set of devices
*/
public void refresh() {
cache.refresh();
public Set<UiDevice> getDevices() {
return cache.getAllDevices();
}
/**
* Returns the set of hosts stored in the model cache.
*
* @return set of hosts
*/
public Set<UiHost> getHosts() {
return cache.getAllHosts();
}
/**
* Returns the set of links stored in the model cache.
*
* @return set of links
*/
public Set<UiLink> getLinks() {
return cache.getAllLinks();
}
// =====================================================================
......
......@@ -18,8 +18,20 @@
<command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
<command>
<action class="org.onosproject.ui.impl.topo.cli.ListMembers"/>
</command>
<command>
<action class="org.onosproject.ui.impl.topo.cli.ListRegions"/>
</command>
<command>
<action class="org.onosproject.ui.impl.topo.cli.ListDevices"/>
</command>
<command>
<action class="org.onosproject.ui.impl.topo.cli.ListHosts"/>
</command>
<command>
<action class="org.onosproject.ui.impl.topo.cli.ListLinks"/>
</command>
</command-bundle>
<!--<bean id="macIDCompleter" class="org.onosproject.dhcp.cli.MacIdCompleter"/>-->
......