use of com.emc.storageos.db.client.model.Network in project coprhd-controller by CoprHD.
the class NetworkAssignedVirtualArraysMigrationTest method prepareData.
@SuppressWarnings("deprecation")
@Override
protected void prepareData() throws Exception {
// Create a virtual array.
VirtualArray varray = new VirtualArray();
varrayURI = URIUtil.createId(VirtualArray.class);
varray.setId(varrayURI);
_dbClient.createObject(varray);
// Create a network and set the virtual array.
Network network = new Network();
network.setId(URIUtil.createId(Network.class));
network.setLabel("NetworkWithVarray");
network.setVirtualArray(varrayURI);
_dbClient.createObject(network);
// Create another network without a virtual array.
network = new Network();
network.setId(URIUtil.createId(Network.class));
network.setLabel("NetworkWithoutVArray");
_dbClient.createObject(network);
}
use of com.emc.storageos.db.client.model.Network in project coprhd-controller by CoprHD.
the class NetworkConnectedVirtualArraysMigrationTest method verifyResults.
@Override
protected void verifyResults() throws Exception {
List<URI> networkURIs = _dbClient.queryByType(Network.class, false);
Iterator<Network> networksIter = _dbClient.queryIterativeObjects(Network.class, networkURIs);
while (networksIter.hasNext()) {
Network network = networksIter.next();
String networkLabel = network.getLabel();
if (network.getLabel().equals("networkAllNull")) {
Assert.assertTrue(String.format("Network (label=%s) should have no assigned or connected varrays", networkLabel), ((network.getAssignedVirtualArrays() == null) && (network.getConnectedVirtualArrays() == null)));
} else if (network.getLabel().equals("networkAssignedOnly")) {
Assert.assertTrue(String.format("Network (label=%s) should have 1 assigned and 1 connected varray", networkLabel), ((network.getAssignedVirtualArrays().size() == 1) && (network.getConnectedVirtualArrays().size() == 1)));
Assert.assertTrue(String.format("Network (label=%s) should have the same varray in assigned and connected", networkLabel), (network.getAssignedVirtualArrays().iterator().next().equals(network.getConnectedVirtualArrays().iterator().next())));
Assert.assertTrue(String.format("Network (label=%s) should have 'assignedVarray' in connected", networkLabel), (assignedVarray.getId().toString().equals(network.getConnectedVirtualArrays().iterator().next())));
} else if (network.getLabel().equals("networkConnectedOnly")) {
Assert.assertTrue(String.format("Network (label=%s) should have no assigned varrays", networkLabel), (network.getAssignedVirtualArrays() == null));
Assert.assertTrue(String.format("Network (label=%s) should have 1 connected varray", networkLabel), (network.getConnectedVirtualArrays().size() == 1));
Assert.assertTrue(String.format("Network (label=%s) should have 'connectedVarray' in connected", networkLabel), (connectedVarray.getId().toString().equals(network.getConnectedVirtualArrays().iterator().next())));
} else if (network.getLabel().equals("networkAssignedAndConnected")) {
Assert.assertTrue(String.format("Network (label=%s) should have 2 assigned varrays", networkLabel), (network.getAssignedVirtualArrays().size() == 2));
Assert.assertTrue(String.format("Network (label=%s) should have 3 connected varray", networkLabel), (network.getConnectedVirtualArrays().size() == 3));
Assert.assertTrue(String.format("Network (label=%s) should have 'assignedVarray' in connected", networkLabel), (network.getConnectedVirtualArrays().contains(assignedVarray.getId().toString())));
Assert.assertTrue(String.format("Network (label=%s) should have 'connectedVarray' in connected", networkLabel), (network.getConnectedVirtualArrays().contains(connectedVarray.getId().toString())));
Assert.assertTrue(String.format("Network (label=%s) should have 'connectedAndassignedVarray' in connected", networkLabel), (network.getConnectedVirtualArrays().contains(connectedAndassignedVarray.getId().toString())));
}
}
}
use of com.emc.storageos.db.client.model.Network in project coprhd-controller by CoprHD.
the class StoragePortConnectedVirtualArraysMigrationTest method prepareData.
@SuppressWarnings("deprecation")
@Override
protected void prepareData() throws Exception {
// Create a virtual array.
VirtualArray varray = new VirtualArray();
varrayURI = URIUtil.createId(VirtualArray.class);
varray.setId(varrayURI);
_dbClient.createObject(varray);
// Create a network and set the virtual array.
Network networkWithVArray = new Network();
URI networkWithVArrayURI = URIUtil.createId(Network.class);
networkWithVArray.setId(networkWithVArrayURI);
networkWithVArray.setLabel("NetworkWithVarray");
networkWithVArray.setVirtualArray(varrayURI);
_dbClient.createObject(networkWithVArray);
// Create another network without a virtual array.
Network networkWithoutVArray = new Network();
URI networkWithoutVArrayURI = URIUtil.createId(Network.class);
networkWithoutVArray.setId(networkWithoutVArrayURI);
networkWithoutVArray.setLabel("NetworkWithoutVArray");
_dbClient.createObject(networkWithoutVArray);
// Create a storage port and set the network for
// storage port to the network assigned to the
// virtual array.
StoragePort storagePortWithConnectedVArray = new StoragePort();
storagePortWithConnectedVArray.setId(URIUtil.createId(Network.class));
storagePortWithConnectedVArray.setLabel("StoragePortWithConnectedVArray");
storagePortWithConnectedVArray.setNetwork(networkWithVArrayURI);
_dbClient.createObject(storagePortWithConnectedVArray);
// Create a storage port and set the network for
// storage port to the network that is not assigned
// to the virtual array.
StoragePort storagePortWithoutConnectedVArray = new StoragePort();
storagePortWithoutConnectedVArray.setId(URIUtil.createId(Network.class));
storagePortWithoutConnectedVArray.setLabel("StoragePortWithoutConnectedVArray");
storagePortWithoutConnectedVArray.setNetwork(networkWithoutVArrayURI);
_dbClient.createObject(storagePortWithoutConnectedVArray);
// Create s storage port without and assigned network.
StoragePort storagePortWithoutNetwork = new StoragePort();
storagePortWithoutNetwork.setId(URIUtil.createId(Network.class));
storagePortWithoutNetwork.setLabel("StoragePortWithoutNetwork");
_dbClient.createObject(storagePortWithoutNetwork);
}
use of com.emc.storageos.db.client.model.Network in project coprhd-controller by CoprHD.
the class StoragePortNetworkIndexMigrationTest method prepareData.
/*
* (non-Javadoc)
*
* @see com.emc.storageos.db.server.upgrade.DbSimpleMigrationTestBase#prepareData()
*/
@Override
protected void prepareData() throws Exception {
DbClient dbClient = getDbClient();
stoPortId1 = URIUtil.createId(VirtualArray.class);
stoPortId2 = URIUtil.createId(VirtualArray.class);
networkId1 = URIUtil.createId(Network.class);
StoragePort stoPort1 = new StoragePort();
stoPort1.setId(stoPortId1);
stoPort1.setLabel("storagePort1");
stoPort1.setPortNetworkId(networkId1.toString());
dbClient.createObject(stoPort1);
StoragePort stoPort2 = new StoragePort();
stoPort2.setId(stoPortId2);
stoPort2.setLabel("storagePort2");
stoPort2.setNetwork(networkId1);
dbClient.createObject(stoPort2);
// verify that we've reproduced the issue
List<StoragePort> stoPorts = CustomQueryUtility.queryActiveResourcesByAltId(dbClient, StoragePort.class, "portNetworkId", networkId1.toString());
Assert.assertEquals(2, stoPorts.size());
List<StoragePort> stoPorts2 = CustomQueryUtility.queryActiveResourcesByAltId(dbClient, StoragePort.class, "network", networkId1.toString());
Assert.assertEquals(2, stoPorts2.size());
}
use of com.emc.storageos.db.client.model.Network in project coprhd-controller by CoprHD.
the class ExternalDeviceCommunicationInterface method discoverStoragePorts.
private Map<String, List<com.emc.storageos.db.client.model.StoragePort>> discoverStoragePorts(DiscoveryDriver driver, Set<Network> networksToUpdate, AccessProfile accessProfile) throws BaseCollectionException {
URI storageSystemId = accessProfile.getSystemId();
com.emc.storageos.db.client.model.StorageSystem storageSystem = _dbClient.queryObject(com.emc.storageos.db.client.model.StorageSystem.class, storageSystemId);
Map<String, List<com.emc.storageos.db.client.model.StoragePort>> storagePorts = new HashMap<>();
Map<StoragePort, com.emc.storageos.db.client.model.StoragePort> driverPortsToDBPorts = new HashMap<>();
List<com.emc.storageos.db.client.model.StoragePort> newStoragePorts = new ArrayList<>();
List<com.emc.storageos.db.client.model.StoragePort> existingStoragePorts = new ArrayList<>();
List<String> endpoints = new ArrayList<>();
StorageSystem driverStorageSystem = initStorageSystem(storageSystem);
// Discover storage ports
try {
_log.info("discoverPorts for storage system {} - start", storageSystemId);
List<StoragePort> driverStoragePorts = new ArrayList<>();
// Call driver.
DriverTask task = driver.discoverStoragePorts(driverStorageSystem, driverStoragePorts);
// todo: need to implement support for async case.
if (task.getStatus() == DriverTask.TaskStatus.READY) {
for (StoragePort driverPort : driverStoragePorts) {
com.emc.storageos.db.client.model.StoragePort storagePort = null;
String portNativeGuid = NativeGUIDGenerator.generateNativeGuid(storageSystem, driverPort.getNativeId(), NativeGUIDGenerator.PORT);
// Check if storage port was already discovered
@SuppressWarnings("deprecation") List<URI> portURIs = _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStoragePortByNativeGuidConstraint(portNativeGuid));
for (URI portUri : portURIs) {
com.emc.storageos.db.client.model.StoragePort port = _dbClient.queryObject(com.emc.storageos.db.client.model.StoragePort.class, portUri);
if (port.getStorageDevice().equals(storageSystemId) && !port.getInactive()) {
storagePort = port;
break;
}
}
// Verify that discovered port has mandatory identifier "portNetworkId"
if (driverPort.getPortNetworkId() == null) {
if (storagePort == null) {
_log.error("No portNetworkId for new discovered port {}, skip discovery of this port.", portNativeGuid);
} else {
_log.error("No portNetworkId for previously discovered port {}, skip discovery of this port.", portNativeGuid);
}
continue;
}
if (storagePort == null) {
// New port processing
storagePort = new com.emc.storageos.db.client.model.StoragePort();
prepareNewPort(storagePort, driverPort);
storagePort.setNativeGuid(portNativeGuid);
storagePort.setStorageDevice(storageSystemId);
if (driverPort.getNetworkId() != null) {
// Get or create Network object for this port
Network portNetwork = getNetworkForStoragePort(driverPort);
storagePort.setNetwork(portNetwork.getId());
// Add endpoint to the network.
// Process this for all ports (existing port got a network or changed network cases)
// TODO: should we check if existing port was in other network and delete the endpoint from the old network?
portNetwork.addEndpoints(new ArrayList<>(Arrays.asList(driverPort.getPortNetworkId())), true);
networksToUpdate.add(portNetwork);
}
storagePort.setTcpPortNumber(driverPort.getTcpPortNumber());
storagePort.setRegistrationStatus(DiscoveredDataObject.RegistrationStatus.REGISTERED.toString());
_log.info("Creating new storage port using NativeGuid : {}", portNativeGuid);
newStoragePorts.add(storagePort);
} else {
existingStoragePorts.add(storagePort);
}
storagePort.setPortNetworkId(driverPort.getPortNetworkId());
if (driverPort.getTransportType() != null && driverPort.getTransportType().equalsIgnoreCase(StoragePort.TransportType.IP.toString())) {
storagePort.setIpAddress(driverPort.getIpAddress());
}
storagePort.setDiscoveryStatus(DiscoveredDataObject.DiscoveryStatus.VISIBLE.name());
storagePort.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name());
storagePort.setOperationalStatus(driverPort.getOperationalStatus());
storagePort.setAvgBandwidth(driverPort.getAvgBandwidth());
storagePort.setPortSpeed(driverPort.getPortSpeed());
// Set usage metric for the port
if (driverPort.getUtilizationMetric() != null) {
StringMap usageMetrics = storagePort.getMetrics();
MetricsKeys.putDouble(MetricsKeys.portMetric, driverPort.getUtilizationMetric(), usageMetrics);
storagePort.setMetrics(usageMetrics);
}
driverPortsToDBPorts.put(driverPort, storagePort);
}
storagePorts.put(NEW, newStoragePorts);
storagePorts.put(EXISTING, existingStoragePorts);
// Create storage ha domains for ports
processStorageHADomains(storageSystem, Collections.unmodifiableMap(driverPortsToDBPorts));
} else {
String errorMsg = String.format("Failed to discover storage ports for system %s of type %s. \n" + " Driver task message: %s", accessProfile.getSystemId(), accessProfile.getSystemType(), task.getMessage());
throw new ExternalDeviceCollectionException(false, ServiceCode.DISCOVERY_ERROR, null, errorMsg, null, null);
}
String message = String.format("Storage ports of storage array %s with native id %s were discovered successfully.", storageSystem.getId(), storageSystem.getNativeGuid());
_log.info(message);
return storagePorts;
} catch (Exception e) {
String message = String.format("Failed to discover storage ports of storage array %s with native id %s : %s .", storageSystem.getId(), storageSystem.getNativeGuid(), e.getMessage());
_log.error(message, e);
storageSystem.setLastDiscoveryStatusMessage(message);
throw e;
} finally {
_dbClient.updateObject(storageSystem);
_log.info("Discovery of storage ports of storage system {} of type {} - end", accessProfile.getSystemId(), accessProfile.getSystemType());
}
}
Aggregations