boolean createOrd = false;
for (final ServiceInfo serviceInfo : servicesAll) {
final boolean isFrom = servicesFrom.contains(serviceInfo);
final String idToAdd = serviceInfo.getService().getCrmId();
if (colocation) {
final ClusterStatus clStatus = getBrowser().getClusterStatus();
/* colocation */
if (colId == null) {
final List<String> rscIds = new ArrayList<String>();
rscIds.add(idToAdd);
int colIdInt = Integer.parseInt(getService().getId());
colId = "c" + colIdInt;
while (clStatus.getRscSetsCol(colId) != null) {
colIdInt++;
colId = "c" + colIdInt;
}
createCol = true;
if (isFrom) {
/* require all for col is noop in pcmk 1.1.7 */
colRscSet2 = new CrmXml.RscSet(colId,
new ArrayList<String>(),
"false",
requireAll,
null,
null);
colRscSet1 = new CrmXml.RscSet(colId,
rscIds,
"false",
CrmXml.REQUIRE_ALL_TRUE_VALUE.getValueForConfig(),
null,
null);
outColRscSet1 = colRscSet1;
} else {
colRscSet2 = new CrmXml.RscSet(colId,
rscIds,
"false",
CrmXml.REQUIRE_ALL_TRUE_VALUE.getValueForConfig(),
null,
null);
colRscSet1 = new CrmXml.RscSet(colId,
new ArrayList<String>(),
"false",
requireAll,
null,
null);
outColRscSet2 = colRscSet2;
}
} else {
final CrmXml.RscSet toRscSet;
if (isFrom) {
if (outColRscSet1 == null) {
toRscSet = colRscSet1;
} else {
toRscSet = outColRscSet1;
}
} else {
if (outColRscSet2 == null) {
toRscSet = colRscSet2;
} else {
toRscSet = outColRscSet2;
}
}
final List<CrmXml.RscSet> rscSetsColList = clStatus.getRscSetsCol(colId);
boolean colRscSetAdded = false;
if (rscSetsColList != null) {
for (final CrmXml.RscSet rscSet : rscSetsColList) {
if (rscSet.equals(toRscSet)) {
final List<String> newRscIds = new ArrayList<String>();
newRscIds.addAll(rscSet.getRscIds());
newRscIds.add(0, idToAdd);
final CrmXml.RscSet newRscSet = new CrmXml.RscSet(rscSet.getId(),
newRscIds,
rscSet.getSequential(),
rscSet.getRequireAll(),
rscSet.getOrderAction(),
rscSet.getColocationRole());
if (isFrom) {
outColRscSet1 = newRscSet;
} else {
outColRscSet2 = newRscSet;
}
colRscSetAdded = true;
} else {
if (isFrom) {
outColRscSet2 = rscSet;
} else {
outColRscSet1 = rscSet;
}
}
}
}
if (!colRscSetAdded) {
final List<String> newRscIds = new ArrayList<String>();
final CrmXml.RscSet newRscSet;
if (toRscSet == null) {
newRscSet = new CrmXml.RscSet(colId, newRscIds, "false", requireAll, null, null);
} else {
newRscIds.addAll(toRscSet.getRscIds());
newRscSet = new CrmXml.RscSet(toRscSet.getId(),
newRscIds,
toRscSet.getSequential(),
toRscSet.getRequireAll(),
toRscSet.getOrderAction(),
toRscSet.getColocationRole());
}
newRscSet.addRscId(idToAdd);
if (isFrom) {
outColRscSet1 = newRscSet;
} else {
outColRscSet2 = newRscSet;
}
}
}
}
if (order) {
/* order */
final ClusterStatus clStatus = getBrowser().getClusterStatus();
if (ordId == null) {
final List<String> rscIds = new ArrayList<String>();
rscIds.add(idToAdd);
int ordIdInt = Integer.parseInt(getService().getId());
ordId = "o" + ordIdInt;
while (clStatus.getRscSetsOrd(ordId) != null) {
ordIdInt++;
ordId = "o" + ordIdInt;
}
createOrd = true;
if (isFrom) {
ordRscSet1 = new CrmXml.RscSet(ordId,
rscIds,
"false",
CrmXml.REQUIRE_ALL_TRUE_VALUE.getValueForConfig(),
null,
null);
ordRscSet2 = new CrmXml.RscSet(ordId,
new ArrayList<String>(),
"false",
requireAll,
null,
null);
outOrdRscSet1 = ordRscSet1;
} else {
ordRscSet1 = new CrmXml.RscSet(ordId,
new ArrayList<String>(),
"false",
requireAll,
null,
null);
ordRscSet2 = new CrmXml.RscSet(ordId,
rscIds,
"false",
CrmXml.REQUIRE_ALL_TRUE_VALUE.getValueForConfig(),
null,
null);
outOrdRscSet2 = ordRscSet2;
}
} else {
final CrmXml.RscSet toRscSet;
if (isFrom) {
if (outOrdRscSet1 == null) {
toRscSet = ordRscSet1;
} else {
toRscSet = outOrdRscSet1;
}
} else {
if (outOrdRscSet2 == null) {
toRscSet = ordRscSet2;
} else {
toRscSet = outOrdRscSet2;
}
}
final List<CrmXml.RscSet> rscSetsOrdList = clStatus.getRscSetsOrd(ordId);
boolean ordRscSetAdded = false;
if (rscSetsOrdList != null) {
for (final CrmXml.RscSet rscSet : rscSetsOrdList) {
if (rscSet.equals(toRscSet)) {
final List<String> newRscIds = new ArrayList<String>();