public void setAllResources(final ClusterStatus clStatus, final Application.RunMode runMode) {
if (clStatus == null) {
return;
}
final Set<String> allGroupsAndClones = clStatus.getAllGroups();
final CrmGraph hg = getBrowser().getCrmGraph();
final List<ServiceInfo> groupServiceIsPresent = new ArrayList<ServiceInfo>();
final List<ServiceInfo> serviceIsPresent = new ArrayList<ServiceInfo>();
for (final String groupOrClone : allGroupsAndClones) {
CloneInfo newCi = null;
GroupInfo newGi = null;
if (clStatus.isClone(groupOrClone)) {
/* clone */
newCi = setCreateCloneInfo(groupOrClone, clStatus, runMode);
serviceIsPresent.add(newCi);
} else if (!"none".equals(groupOrClone)) {
/* group */
final GroupInfo gi = (GroupInfo) getBrowser().getServiceInfoFromCRMId(groupOrClone);
if (gi != null && gi.getCloneInfo() != null) {
/* cloned group is already done */
groupServiceIsPresent.add(gi);
continue;
}
newGi = setCreateGroupInfo(groupOrClone, newCi, clStatus, runMode);
serviceIsPresent.add(newGi);
}
setGroupResources(allGroupsAndClones,
groupOrClone,
newGi,
newCi,
serviceIsPresent,
groupServiceIsPresent,
clStatus,
runMode);
}
hg.clearKeepColocationList();
hg.clearKeepOrderList();
/* resource sets */
final List<CrmXml.RscSetConnectionData> rscSetConnections = clStatus.getRscSetConnections();
if (rscSetConnections != null) {
final Map<CrmXml.RscSetConnectionData, ConstraintPHInfo> rdataToCphi =
new LinkedHashMap<CrmXml.RscSetConnectionData, ConstraintPHInfo>();
getBrowser().lockNameToServiceInfo();
final Map<String, ServiceInfo> idToInfoHash = getBrowser().getNameToServiceInfoHash(ConstraintPHInfo.NAME);
final List<ConstraintPHInfo> preNewCphis = new ArrayList<ConstraintPHInfo>();
if (idToInfoHash != null) {
for (final Map.Entry<String, ServiceInfo> infoEntry : idToInfoHash.entrySet()) {
final ConstraintPHInfo cphi = (ConstraintPHInfo) infoEntry.getValue();
final CrmXml.RscSetConnectionData rdataOrd = cphi.getRscSetConnectionDataOrder();
final CrmXml.RscSetConnectionData rdataCol = cphi.getRscSetConnectionDataColocation();
if (cphi.getService().isNew()) {
preNewCphis.add(cphi);
}
if (rdataOrd != null && !rdataOrd.isEmpty()) {
rdataToCphi.put(rdataOrd, cphi);
}
if (rdataCol != null && !rdataCol.isEmpty()) {
rdataToCphi.put(rdataCol, cphi);
}
}
}
getBrowser().unlockNameToServiceInfo();
final Collection<ConstraintPHInfo> newCphis = new ArrayList<ConstraintPHInfo>();
for (final CrmXml.RscSetConnectionData rdata : rscSetConnections) {
ConstraintPHInfo constraintPHInfo = null;
for (final Map.Entry<CrmXml.RscSetConnectionData, ConstraintPHInfo> phEntry : rdataToCphi.entrySet()) {
if (phEntry.getKey() == rdata) {
continue;
}
if (rdata.equals(phEntry.getKey()) || rdata.equalsAlthoughReversed(phEntry.getKey())) {
constraintPHInfo = phEntry.getValue();
constraintPHInfo.setRscSetConnectionData(rdata);
break;
}
}
PcmkRscSetsInfo rscSetsInfo = null;
if (constraintPHInfo == null) {
for (final Map.Entry<CrmXml.RscSetConnectionData, ConstraintPHInfo> phEntry
: rdataToCphi.entrySet()) {
if (phEntry.getKey() == rdata) {
constraintPHInfo = phEntry.getValue();
break;
}
if (phEntry.getValue().sameConstraintId(rdata)) {
/* use the same rsc set info object */
rscSetsInfo = phEntry.getValue().getPcmkRscSetsInfo();
}
if (phEntry.getValue().getService().isNew()
|| (rdata.canUseSamePlaceholder(phEntry.getKey())
&& phEntry.getValue().sameConstraintId(rdata))) {
constraintPHInfo = phEntry.getValue();
constraintPHInfo.setRscSetConnectionData(rdata);
rscSetsInfo = constraintPHInfo.getPcmkRscSetsInfo();
if (rscSetsInfo != null) {
if (rdata.isColocation()) {
rscSetsInfo.addColocation(rdata.getConstraintId(), constraintPHInfo);
} else {
rscSetsInfo.addOrder(rdata.getConstraintId(), constraintPHInfo);
}
}
break;
}
}
}
if (constraintPHInfo == null && !preNewCphis.isEmpty()) {
/* placeholder */
constraintPHInfo = preNewCphis.remove(0);
rdataToCphi.put(rdata, constraintPHInfo);
constraintPHInfo.setRscSetConnectionData(rdata);
}
if (constraintPHInfo == null) {
constraintPHInfo = constraintPHInfoProvider.get();
constraintPHInfo.init(getBrowser(), rdata, ConstraintPHInfo.Preference.AND);
if (rscSetsInfo == null) {
rscSetsInfo = pcmkRscSetsInfoProvider.get();
rscSetsInfo.init(getBrowser());
}
if (rdata.isColocation()) {
rscSetsInfo.addColocation(rdata.getConstraintId(), constraintPHInfo);
} else {
rscSetsInfo.addOrder(rdata.getConstraintId(), constraintPHInfo);
}
constraintPHInfo.setPcmkRscSetsInfo(rscSetsInfo);
getBrowser().addNameToServiceInfoHash(constraintPHInfo);
newCphis.add(constraintPHInfo); /* have to add it later,
so that ids are correct. */
rdataToCphi.put(rdata, constraintPHInfo);
}
serviceIsPresent.add(constraintPHInfo);
final CrmXml.RscSet rscSet1 = rdata.getRscSet1();
final CrmXml.RscSet rscSet2 = rdata.getRscSet2();
if (rdata.isColocation()) {
/* colocation */
if (rscSet1 != null) {
for (final String rscId : rscSet1.getRscIds()) {
final ServiceInfo si =
getBrowser().getServiceInfoFromCRMId(rscId);
hg.addColocation(rdata.getConstraintId(), constraintPHInfo, si);
}
}
if (rscSet2 != null) {
for (final String rscId : rscSet2.getRscIds()) {
final ServiceInfo si = getBrowser().getServiceInfoFromCRMId( rscId);
hg.addColocation(rdata.getConstraintId(), si, constraintPHInfo);
}
}
} else {
/* order */
if (rscSet1 != null) {
for (final String rscId : rscSet1.getRscIds()) {
final ServiceInfo si = getBrowser().getServiceInfoFromCRMId( rscId);
hg.addOrder(rdata.getConstraintId(), si, constraintPHInfo);
}
}
if (rscSet2 != null) {
for (final String rscId : rscSet2.getRscIds()) {
final ServiceInfo si = getBrowser().getServiceInfoFromCRMId(rscId);
hg.addOrder(rdata.getConstraintId(), constraintPHInfo, si);
}
}
}
if (Application.isLive(runMode)) {
constraintPHInfo.setUpdated(false);
constraintPHInfo.getService().setNew(false);
}
}
for (final ConstraintPHInfo cphi : newCphis) {
hg.addConstraintPlaceholder(cphi,
null, /* pos */
Application.RunMode.LIVE);
}
}
/* colocations */
final Map<String, List<CrmXml.ColocationData>> colocationMap = clStatus.getColocationRscMap();
for (final Map.Entry<String, List<CrmXml.ColocationData>> colocationEntry : colocationMap.entrySet()) {
final List<CrmXml.ColocationData> withs = colocationEntry.getValue();
for (final CrmXml.ColocationData data : withs) {
final String withRscId = data.getWithRsc();
final ServiceInfo withSi = getBrowser().getServiceInfoFromCRMId(withRscId);
final ServiceInfo siP = getBrowser().getServiceInfoFromCRMId(colocationEntry.getKey());
hg.addColocation(data.getId(), siP, withSi);
}
}
/* orders */
final Map<String, List<CrmXml.OrderData>> orderMap = clStatus.getOrderRscMap();
for (final Map.Entry<String, List<CrmXml.OrderData>> orderEntry : orderMap.entrySet()) {
for (final CrmXml.OrderData data : orderEntry.getValue()) {
final String rscThenId = data.getRscThen();
final ServiceInfo si = getBrowser().getServiceInfoFromCRMId(rscThenId);
if (si != null) { /* not yet complete */
final ServiceInfo siP = getBrowser().getServiceInfoFromCRMId(orderEntry.getKey());
if (siP != null && siP.getResourceAgent() != null) {
/* dangling orders and colocations */
if ((siP.getResourceAgent().isDrbddisk() || siP.getResourceAgent().isLinbitDrbd())
&& "Filesystem".equals(si.getName())) {
final List<CrmXml.ColocationData> cds = clStatus.getColocationDatas(orderEntry.getKey());
if (cds != null) {
for (final CrmXml.ColocationData cd : cds) {
if (cd.getWithRsc().equals(rscThenId)) {
setFilesystemWithDrbd(siP, si);
}
}
}
}
hg.addOrder(data.getId(), siP, si);
}
}
}
}
for (final Info info : treeMenuController.nodesToInfos(getNode().children())) {
final ServiceInfo group = (ServiceInfo) info;
if (group.getResourceAgent().isGroup() || group.getResourceAgent().isClone()) {
for (final Info groupInfo : treeMenuController.nodesToInfos(group.getNode().children())) {
final ServiceInfo groupService = (ServiceInfo) groupInfo;
if (!groupServiceIsPresent.contains(groupService) && !groupService.getService().isNew()) {
/* remove the group service from the menu
that does not exist anymore. */
groupService.removeInfo();
}
}
}
}
hg.setServiceIsPresentList(serviceIsPresent);
/** Set placeholders to "new", if they have no connections. */
application.invokeInEdt(new Runnable() {
@Override
public void run() {
hg.killRemovedEdges();
final Map<String, ServiceInfo> idToInfoHash =
getBrowser().getNameToServiceInfoHash(ConstraintPHInfo.NAME);
if (idToInfoHash != null) {
for (final Map.Entry<String, ServiceInfo> serviceEntry : idToInfoHash.entrySet()) {
final ConstraintPHInfo cphi = (ConstraintPHInfo) serviceEntry.getValue();
if (!cphi.getService().isNew() && cphi.isEmpty()) {
cphi.getService().setNew(true);
}
}
}
hg.killRemovedVertices();
hg.scale();
}
});
}