use of com.emc.storageos.coordinator.client.model.SoftwareVersion in project coprhd-controller by CoprHD.
the class RemoteRepository method finInstallableVersionsFromCatalogRepo.
private List<SoftwareVersion> finInstallableVersionsFromCatalogRepo(String catalogString, List<SoftwareVersion> newVersionList, List<SoftwareVersion> localVersions) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException, InvalidSoftwareVersionException, MalformedURLException, RemoteRepositoryException {
List<SoftwareVersion> validVersions = new ArrayList<SoftwareVersion>();
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(new InputSource(new StringReader(catalogString)));
XPath xPath = XPathFactory.newInstance().newXPath();
NodeList fileList = (NodeList) xPath.compile("//File").evaluate(doc, XPathConstants.NODESET);
OUTER: for (int fileItr = 0; fileItr < fileList.getLength(); fileItr++) {
Node fileNode = fileList.item(fileItr);
Element element = (Element) fileNode;
Node nameNode = element.getAttributeNode("Name");
if (null != nameNode) {
String fileName = nameNode.getNodeValue();
if (fileName.endsWith(SOFTWARE_IMAGE_SUFFIX)) {
String fileVersion = fileName.replace(SOFTWARE_IMAGE_SUFFIX, "");
SoftwareVersion tempVersion = new SoftwareVersion(fileVersion);
if (newVersionList.contains(tempVersion)) {
Node catalogInfoNode = element.getAttributeNode("CatalogInfo");
String catalogInfo = catalogInfoNode.getNodeValue();
if (catalogInfo.equals("")) {
// Ignore the version that doesn't have the upgradeFromVersion metadata
continue;
}
// key-value pairs are separated by comma
String upgradeFromInfoRaw = catalogInfo.split(",")[0];
// only need the value
String upgradeFromInfo = upgradeFromInfoRaw.split("=")[1];
for (String versionStr : upgradeFromInfo.split(";")) {
// versions are separated by semicolon
for (SoftwareVersion v : localVersions) {
if (new SoftwareVersion(versionStr).weakEquals(v)) {
// wild card is used in the upgradeFromVersions list,
// need use weakEquals
validVersions.add(tempVersion);
continue OUTER;
}
}
}
}
}
}
}
return validVersions;
}
use of com.emc.storageos.coordinator.client.model.SoftwareVersion in project coprhd-controller by CoprHD.
the class SyncInfoBuilder method findToRemove.
public static List<SoftwareVersion> findToRemove(final List<SoftwareVersion> localVersions, final SoftwareVersion localCurrent, final SoftwareVersion remoteCurrent, final SoftwareVersion toInstall, final boolean force) throws IOException {
List<SoftwareVersion> sortedList = new ArrayList<SoftwareVersion>(localVersions);
Collections.sort(sortedList);
List<SoftwareVersion> toRemove = new ArrayList<SoftwareVersion>();
if (force || sortedList.size() > MAX_SOFTWARE_VERSIONS) {
for (SoftwareVersion v : sortedList) {
if (!v.equals(localCurrent) && !v.equals(remoteCurrent) && isRemovable(sortedList, v)) {
toRemove.add(v);
}
}
}
return toRemove;
}
use of com.emc.storageos.coordinator.client.model.SoftwareVersion in project coprhd-controller by CoprHD.
the class SyncInfoBuilder method isRemovable.
// Method to test if a version is removable.
// The first or the last version in the list is removable.
// Version that cannot be upgraded from its previous versions is removable.
// Version that cannot upgrade to its following versions is removable.
// Version a in a list x can upgrade to a list of versions. Those versions form a list y. If any version from list y have at least one
// version other than target
// version to upgrade from, the version a is removable otherwise it's not removable
// Note that the maximum versions allowed is 4.
private static boolean isRemovable(List<SoftwareVersion> versions, SoftwareVersion version) throws IOException {
int index = versions.indexOf(version);
int size = versions.size();
if (index == 0 || index == size - 1) {
// if the tested version is the first or last version in the list it will not cause further inconsistency for sure
return true;
}
// Get lists of versions that target version can upgrade from and upgrade to
List<SoftwareVersion> upgradeFromVersionList = new ArrayList<SoftwareVersion>();
List<SoftwareVersion> upgradeToVersionList = new ArrayList<SoftwareVersion>();
for (int i = 0; i < index; i++) {
SoftwareVersion tempVersion = versions.get(i);
if (tempVersion.isSwitchableTo(version)) {
upgradeFromVersionList.add(tempVersion);
}
}
for (int i = index + 1; i < size; i++) {
SoftwareVersion tempVersion = versions.get(i);
if (version.isSwitchableTo(tempVersion)) {
upgradeToVersionList.add(tempVersion);
}
}
if (upgradeFromVersionList.isEmpty() || upgradeToVersionList.isEmpty()) {
// If no version can upgrade to the target version or no version can be upgrade from the target version, target
return true;
// version is removable
}
OUTLOOP: for (SoftwareVersion v : upgradeToVersionList) {
int position = versions.indexOf(v);
for (int i = 0; i < position; i++) {
if (i != index && versions.get(i).isSwitchableTo(v)) {
continue OUTLOOP;
// If this version can be upgrade from a version other than the target continue to test the next version
}
}
// If this version doesn't have any version to upgrade from, false should be returned
return false;
}
// All versions from the upgradeToVersionList have versions other than the target version to upgrade from, true should
return true;
// be returned
}
use of com.emc.storageos.coordinator.client.model.SoftwareVersion in project coprhd-controller by CoprHD.
the class SyncInfoBuilder method getTargetSyncInfo.
/**
* Select a SoftwareVersion from the leader repository list that can be installed,
* and a list of versions that have to be removed from the local repository.
*
* @return SyncInfo - An immutable Selector object with a SoftwareVersion toInstall and
* a list of SoftwareVersions to toRemove. The toInstall might be null.
* The toRemove might be empty (but not null).
* @throws IOException
* @see SyncInfo
*/
public static SyncInfo getTargetSyncInfo(final RepositoryInfo local, final RepositoryInfo target) {
final SoftwareVersion localCurrent = (local != null) ? local.getCurrentVersion() : null;
final List<SoftwareVersion> localVersions = (local != null && local.getVersions() != null) ? local.getVersions() : new ArrayList<SoftwareVersion>();
final SoftwareVersion targetCurrent = (target != null) ? target.getCurrentVersion() : null;
final List<SoftwareVersion> targetVersions = (target != null && target.getVersions() != null) ? target.getVersions() : new ArrayList<SoftwareVersion>();
// Basic validations
if (localCurrent == null || localVersions == null || localVersions.isEmpty()) {
log.error("inconsistent local repository state");
return new SyncInfo();
}
if (targetCurrent == null || targetVersions == null || targetVersions.isEmpty()) {
log.error("inconsistent target repository state");
return new SyncInfo();
}
final String args = MessageFormat.format("local: [{0}/{1}] current={2} versions={3} " + "remote: current {4} versions={5}", localVersions.size(), MAX_SOFTWARE_VERSIONS, localCurrent, Strings.repr(localVersions), targetCurrent, Strings.repr(targetVersions));
final String prefix = "getTargetSyncInfo(): " + args + " : ";
// Set force to true as we already did the version check during set_target call
if (targetCurrent != null && !targetCurrent.equals(localCurrent) && !localVersions.contains(targetCurrent)) {
try {
if (!localCurrent.isSwitchableTo(targetCurrent)) {
// we are not expecting this case - don't change anything, wait for help!
log.error("{} local current not upgradable to current on leader", prefix);
return new SyncInfo();
}
} catch (IOException e) {
log.error("Error occured when extracting version metadata from the image file", e);
}
}
// To Install - what version do the target state have that I don't have
List<SoftwareVersion> toInstallCandidates = new ArrayList<SoftwareVersion>(targetVersions);
Collections.sort(toInstallCandidates);
for (SoftwareVersion version : toInstallCandidates) {
if (localVersions.contains(version)) {
continue;
}
return new SyncInfo(version, new ArrayList<SoftwareVersion>());
}
// if we are here, we didn't find anything to install - see if we need to remove any
// To Remove - what versions do I have that the target does not have
// Set force to true as we already did the version check during set_target call
List<SoftwareVersion> toRemoveCandidates = new ArrayList<SoftwareVersion>();
try {
toRemoveCandidates = findToRemove(localVersions, localCurrent, null, null, true);
} catch (IOException e) {
log.error("Error occured when extracting version metadata from the image file", e);
}
List<SoftwareVersion> toRemove = new ArrayList<SoftwareVersion>();
for (SoftwareVersion version : toRemoveCandidates) {
if (targetVersions.contains(version)) {
continue;
}
toRemove.add(version);
return new SyncInfo(toRemove);
}
log.info(prefix + " Nothing to do.");
return new SyncInfo();
}
use of com.emc.storageos.coordinator.client.model.SoftwareVersion in project coprhd-controller by CoprHD.
the class UpgradeManager method syncWithRemote.
private boolean syncWithRemote(final RepositoryInfo localInfo, final RepositoryInfo targetInfo, final SyncInfo syncinfo) throws RemoteRepositoryException, LocalRepositoryException {
// Step1 - if something to install, install
if (syncinfo.getToInstall() != null && !syncinfo.getToInstall().isEmpty()) {
final SoftwareVersion toInstall = syncinfo.getToInstall().get(0);
File image = null;
if (toInstall != null && (image = getRemoteImage(toInstall)) == null) {
return false;
}
if (image != null) {
try {
localRepository.installImage(image);
} finally {
image.delete();
}
}
}
// Step2 - if something to remove, remove
if (syncinfo.getToRemove() != null && !syncinfo.getToRemove().isEmpty()) {
for (SoftwareVersion v : syncinfo.getToRemove()) {
localRepository.removeVersion(v);
}
}
return true;
}
Aggregations