Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #503 from priley86/deleted-network
Browse files Browse the repository at this point in the history
[#499] handle missing clusters, networks, storages
  • Loading branch information
AparnaKarve authored Jul 19, 2018
2 parents b7a0e17 + 607e231 commit 85699b7
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,31 @@ class InfrastructureMappingsList extends React.Component {

let sourceClusterCount = 0;
let targetClusterCount = 0;
Object.keys(targetClusters).forEach(key => {
targetClusterCount += 1;
sourceClusterCount += targetClusters[key].sourceClusters.length;
});

if (targetClusters) {
Object.keys(targetClusters).forEach(key => {
targetClusterCount += 1;
sourceClusterCount += targetClusters[key].sourceClusters.length;
});
}

let sourceDatastoreCount = 0;
let targetDatastoreCount = 0;
Object.keys(targetDatastores).forEach(key => {
targetDatastoreCount += 1;
sourceDatastoreCount += targetDatastores[key].sources.length;
});
if (targetDatastores) {
Object.keys(targetDatastores).forEach(key => {
targetDatastoreCount += 1;
sourceDatastoreCount += targetDatastores[key].sources.length;
});
}

let sourceLanCount = 0;
let targetLanCount = 0;
Object.keys(targetNetworks).forEach(key => {
targetLanCount += 1;
sourceLanCount += targetNetworks[key].sources.length;
});
if (targetNetworks) {
Object.keys(targetNetworks).forEach(key => {
targetLanCount += 1;
sourceLanCount += targetNetworks[key].sources.length;
});
}

return (
<ListView.Item
Expand All @@ -164,76 +171,97 @@ class InfrastructureMappingsList extends React.Component {
onCloseCompoundExpand={() => this.closeExpand(mapping)}
additionalInfo={[
<ListView.InfoItem key={0} id="networks">
<ListView.Expand
expanded={mapping.expanded && mapping.expandType === 0}
toggleExpanded={() => {
this.toggleExpand(mapping, 0);
}}
>
<Icon type="pf" name="network" />
<div className="mappings-expand-label-group">
<div className="mappings-expand-label">
{sprintf(
n__('%d Source Network', '%d Source Networks', sourceLanCount),
sourceLanCount
)}
</div>
<div className="mappings-expand-label">
{sprintf(
n__('%d Target Network', '%d Target Networks', targetLanCount),
targetLanCount
)}
</div>
{targetNetworks === null ? (
<div className="list-view-pf-expand">
<Icon type="pf" name="error-circle-o" />
{__('Networks missing')}
</div>
</ListView.Expand>
) : (
<ListView.Expand
expanded={mapping.expanded && mapping.expandType === 0}
toggleExpanded={() => {
this.toggleExpand(mapping, 0);
}}
>
<Icon type="pf" name="network" />
<div className="mappings-expand-label-group">
<div className="mappings-expand-label">
{sprintf(
n__('%d Source Network', '%d Source Networks', sourceLanCount),
sourceLanCount
)}
</div>
<div className="mappings-expand-label">
{sprintf(
n__('%d Target Network', '%d Target Networks', targetLanCount),
targetLanCount
)}
</div>
</div>
</ListView.Expand>
)}
</ListView.InfoItem>,
<ListView.InfoItem key={1} id="datastores">
<ListView.Expand
expanded={mapping.expanded && mapping.expandType === 1}
toggleExpanded={() => {
this.toggleExpand(mapping, 1);
}}
>
<Icon type="fa" name="database" />
<div className="mappings-expand-label-group">
<div className="mappings-expand-label">
{sprintf(
n__('%d Source Datastore', '%d Source Datastores', sourceDatastoreCount),
sourceDatastoreCount
)}
</div>
<div className="mappings-expand-label">
{sprintf(
n__('%d Target Datastore', '%d Target Datastores', targetDatastoreCount),
targetDatastoreCount
)}
</div>
{targetDatastores === null ? (
<div className="list-view-pf-expand">
<Icon type="pf" name="error-circle-o" />
{__('Datastores missing')}
</div>
</ListView.Expand>
) : (
<ListView.Expand
expanded={mapping.expanded && mapping.expandType === 1}
toggleExpanded={() => {
this.toggleExpand(mapping, 1);
}}
>
<Icon type="fa" name="database" />
<div className="mappings-expand-label-group">
<div className="mappings-expand-label">
{sprintf(
n__('%d Source Datastore', '%d Source Datastores', sourceDatastoreCount),
sourceDatastoreCount
)}
</div>
<div className="mappings-expand-label">
{sprintf(
n__('%d Target Datastore', '%d Target Datastores', targetDatastoreCount),
targetDatastoreCount
)}
</div>
</div>
</ListView.Expand>
)}
</ListView.InfoItem>,
<ListView.InfoItem key={2} id="clusters">
<ListView.Expand
expanded={mapping.expanded && mapping.expandType === 2}
toggleExpanded={() => {
this.toggleExpand(mapping, 2);
}}
>
<Icon type="pf" name="cluster" />
<div className="mappings-expand-label-group">
<div className="mappings-expand-label">
{sprintf(
n__('%d Source Cluster', '%d Source Clusters', sourceClusterCount),
sourceClusterCount
)}
</div>
<div className="mappings-expand-label">
{sprintf(
n__('%d Target Cluster', '%d Target Clusters', targetClusterCount),
targetClusterCount
)}
</div>
{targetClusters === null ? (
<div className="list-view-pf-expand">
<Icon type="pf" name="error-circle-o" />
{__('Clusters missing')}
</div>
</ListView.Expand>
) : (
<ListView.Expand
expanded={mapping.expanded && mapping.expandType === 2}
toggleExpanded={() => {
this.toggleExpand(mapping, 2);
}}
>
<Icon type="pf" name="cluster" />
<div className="mappings-expand-label-group">
<div className="mappings-expand-label">
{sprintf(
n__('%d Source Cluster', '%d Source Clusters', sourceClusterCount),
sourceClusterCount
)}
</div>
<div className="mappings-expand-label">
{sprintf(
n__('%d Target Cluster', '%d Target Clusters', targetClusterCount),
targetClusterCount
)}
</div>
</div>
</ListView.Expand>
)}
</ListView.InfoItem>,
associatedPlansCount ? (
<ListView.InfoItem key={3} id="associated-plans">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ export const mapInfrastructureMappings = (transformation_mapping_items, clusters

// create unique cluster mappings by unique target cluster
const targetClusters = {};
clusterMappingItems.forEach(clusterMapping => {
for (const clusterMapping of clusterMappingItems) {
const sourceCluster = clusters.find(c => c.id === clusterMapping.source_id);
const targetCluster = clusters.find(c => c.id === clusterMapping.destination_id);

if (sourceCluster && targetCluster) {
if (targetClusters[targetCluster.id]) {
targetClusters[targetCluster.id].sourceClusters.push(sourceCluster);
Expand All @@ -70,8 +71,15 @@ export const mapInfrastructureMappings = (transformation_mapping_items, clusters
targetClusters[targetCluster.id].targetCluster = targetCluster;
targetClusters[targetCluster.id].sourceClusters = [sourceCluster];
}
} else {
// we have missing cluster data, just return null and show missing data
return {
targetClusters: null,
targetDatastores: null,
targetNetworks: null
};
}
});
}

// transform cluster lans and datastores to key/value lookups for use in datastore/lan mappings
const clusterDatastores = {};
Expand All @@ -91,7 +99,8 @@ export const mapInfrastructureMappings = (transformation_mapping_items, clusters

// create unique datastore mappings by unique target datastore
const targetDatastores = {};
datastoreMappingItems.forEach(datastoreMapping => {
let missingDatastores = false;
for (const datastoreMapping of datastoreMappingItems) {
const sourceCluster = clusters.find(c => c.id === clusterDatastores[datastoreMapping.source_id]);
const targetCluster = clusters.find(c => c.id === clusterDatastores[datastoreMapping.destination_id]);
const sourceDatastore = datastores.find(d => d.id === datastoreMapping.source_id);
Expand All @@ -102,7 +111,6 @@ export const mapInfrastructureMappings = (transformation_mapping_items, clusters
sourceDatastore,
sourceCluster
};

const target = {
targetDatastore,
targetCluster
Expand All @@ -114,22 +122,32 @@ export const mapInfrastructureMappings = (transformation_mapping_items, clusters
targetDatastores[targetDatastore.id].target = target;
targetDatastores[targetDatastore.id].sources = [source];
}
} else {
missingDatastores = true;
break;
}
});
}

// create unique networks mappings by unique target network
const targetNetworks = {};
networkMappingItems.forEach(networkMapping => {
let missingNetworks = false;
for (const networkMapping of networkMappingItems) {
if (!(networkMapping.source_id in clusterLans)) {
missingNetworks = true;
break;
}
if (!(networkMapping.destination_id in clusterLans)) {
missingNetworks = true;
break;
}
const sourceCluster = clusters.find(c => c.id === clusterLans[networkMapping.source_id]);
const targetCluster = clusters.find(c => c.id === clusterLans[networkMapping.destination_id]);

const sn = networks.find(d => d.id === networkMapping.source_id);
const sourceNetwork = Immutable.set(sn, 'clusterId', sourceCluster.id);

const tn = networks.find(d => d.id === networkMapping.destination_id);
const targetNetwork = Immutable.set(tn, 'clusterId', targetCluster.id);

if (sourceCluster && targetCluster && sourceNetwork && targetNetwork) {
if (sourceCluster && targetCluster && sn && tn) {
const sourceNetwork = Immutable.set(sn, 'clusterId', sourceCluster.id);
const targetNetwork = Immutable.set(tn, 'clusterId', targetCluster.id);
const source = {
sourceNetwork,
sourceCluster
Expand All @@ -153,12 +171,15 @@ export const mapInfrastructureMappings = (transformation_mapping_items, clusters
targetNetworks[targetNetworkKey].target = target;
targetNetworks[targetNetworkKey].sources = [source];
}
} else {
missingNetworks = true;
break;
}
});
}

return {
targetClusters,
targetDatastores,
targetNetworks
targetDatastores: missingDatastores ? null : targetDatastores,
targetNetworks: missingNetworks ? null : targetNetworks
};
};

0 comments on commit 85699b7

Please sign in to comment.