Search in sources :

Example 26 with SoftwareVersion

use of com.emc.storageos.coordinator.client.model.SoftwareVersion in project coprhd-controller by CoprHD.

the class ConnectVdcTaskOp method checkNetworkTopology.

private String checkNetworkTopology(VdcPreCheckResponse vdcBeingAdded) {
    SoftwareVersion remoteVer = new SoftwareVersion(vdcBeingAdded.getSoftwareVersion());
    if (remoteVer.compareTo(netcheckMinVer) >= 0) {
        String nodeId = this.dbClient.getCoordinatorClient().getPropertyInfo().getProperty("node_id");
        log.info("Retrieving IP addresses of local node: {}, and let remote VDC {} check if we're behind a NAT", nodeId, vdcBeingAdded.getShortId());
        DualInetAddress inetAddress = this.dbClient.getCoordinatorClient().getInetAddessLookupMap().getDualInetAddress();
        String ipv4 = inetAddress.getInet4();
        String ipv6 = inetAddress.getInet6();
        log.info("Got local node's IP addresses, IPv4 = {}, IPv6 = {}", ipv4, ipv6);
        VdcNatCheckParam checkParam = new VdcNatCheckParam();
        checkParam.setIPv4Address(ipv4);
        checkParam.setIPv6Address(ipv6);
        VdcNatCheckResponse resp = geoClientCache.getGeoClient(vdcInfo).vdcNatCheck(checkParam);
        if (resp.isBehindNAT()) {
            return String.format("The remote VDC %s seen this node's IP is %s, which is different from what we think: %s or %s, we may behind a NAT", vdcBeingAdded.getShortId(), resp.getSeenIp(), ipv4, ipv6);
        }
    } else {
        log.info("Remote VDC is of version {}, lower than {}, NAT check skipped.", remoteVer, netcheckMinVer);
    }
    return null;
}
Also used : SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion) VdcNatCheckParam(com.emc.storageos.geomodel.VdcNatCheckParam) VdcNatCheckResponse(com.emc.storageos.geomodel.VdcNatCheckResponse) DualInetAddress(com.emc.storageos.coordinator.client.service.impl.DualInetAddress)

Example 27 with SoftwareVersion

use of com.emc.storageos.coordinator.client.model.SoftwareVersion in project coprhd-controller by CoprHD.

the class RemoteRepository method getUpgradeFromVersionsFromCatalogRepo.

private List<String> getUpgradeFromVersionsFromCatalogRepo(String input, SoftwareVersion version) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException, InvalidSoftwareVersionException, MalformedURLException, RemoteRepositoryException {
    List<String> versions = new ArrayList<String>();
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(new InputSource(new StringReader(input)));
    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, "");
                if (new SoftwareVersion(fileVersion).equals(version)) {
                    // Only find the node for image file of that particular version
                    Node catalogInfoNode = element.getAttributeNode("CatalogInfo");
                    String catalogInfo = catalogInfoNode.getNodeValue();
                    if (catalogInfo == null) {
                        return versions;
                    }
                    String upgradeFromInfoRaw = null;
                    for (String s : catalogInfo.split(",")) {
                        // key-value pairs are separated by comma
                        if (s.startsWith("upgradeFromVersions=")) {
                            upgradeFromInfoRaw = s;
                            break;
                        }
                    }
                    // The format is
                    String upgradeFromInfo = upgradeFromInfoRaw.split("=")[1];
                    // need the key and the equal sign
                    for (String v : upgradeFromInfo.split(";")) {
                        versions.add(v);
                    }
                    break OUTER;
                }
            }
        }
    }
    return versions;
}
Also used : XPath(javax.xml.xpath.XPath) InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion) DocumentBuilder(javax.xml.parsers.DocumentBuilder)

Example 28 with SoftwareVersion

use of com.emc.storageos.coordinator.client.model.SoftwareVersion in project coprhd-controller by CoprHD.

the class RemoteRepositoryCache method decodeFromString.

@SuppressWarnings("unchecked")
@Override
public RemoteRepositoryCache decodeFromString(String swVersionsString) {
    Map<SoftwareVersion, List<SoftwareVersion>> softwareVersionsMap = new HashMap<SoftwareVersion, List<SoftwareVersion>>();
    long lastRefresh = 0L;
    String repositoryUrl = "";
    if (null != swVersionsString) {
        String[] swVersionsArray = swVersionsString.split(PropertyInfoExt.ENCODING_NEWLINE);
        if (swVersionsArray.length >= 2) {
            lastRefresh = Long.parseLong(swVersionsArray[0]);
            repositoryUrl = swVersionsArray[1];
            for (int i = 2; i < swVersionsArray.length; i++) {
                String[] pStrings = swVersionsArray[i].split(PropertyInfoExt.ENCODING_SEPARATOR);
                SoftwareVersion keyVersion = new SoftwareVersion(pStrings[0]);
                List<SoftwareVersion> valueList = new ArrayList<SoftwareVersion>();
                int len = pStrings.length;
                if (len > 1) {
                    for (int j = 1; j < len; j++) {
                        valueList.add(new SoftwareVersion(pStrings[j]));
                    }
                }
                softwareVersionsMap.put(keyVersion, valueList);
            }
        }
    }
    return new RemoteRepositoryCache(softwareVersionsMap, lastRefresh, repositoryUrl);
}
Also used : SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 29 with SoftwareVersion

use of com.emc.storageos.coordinator.client.model.SoftwareVersion in project coprhd-controller by CoprHD.

the class RemoteRepositoryCache method encodeAsString.

@Override
public String encodeAsString() {
    StringBuilder sb = new StringBuilder();
    sb.append(_lastVersionCheck);
    sb.append(PropertyInfoExt.ENCODING_NEWLINE);
    sb.append(_repositoryInfo);
    sb.append(PropertyInfoExt.ENCODING_NEWLINE);
    for (SoftwareVersion softwareVersion : _cachedVersions.keySet()) {
        sb.append(softwareVersion.toString());
        sb.append(PropertyInfoExt.ENCODING_SEPARATOR);
        for (SoftwareVersion s : _cachedVersions.get(softwareVersion)) {
            sb.append(s.toString());
            sb.append(PropertyInfoExt.ENCODING_SEPARATOR);
        }
        sb.append(PropertyInfoExt.ENCODING_NEWLINE);
    }
    return sb.toString();
}
Also used : SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion)

Example 30 with SoftwareVersion

use of com.emc.storageos.coordinator.client.model.SoftwareVersion in project coprhd-controller by CoprHD.

the class SyncInfoBuilder method getInstallableRemoteVersions.

public static List<SoftwareVersion> getInstallableRemoteVersions(final RepositoryInfo local, Map<SoftwareVersion, List<SoftwareVersion>> remoteVersions, final boolean forceInstall) {
    final SoftwareVersion localCurrent = (local != null) ? local.getCurrentVersion() : null;
    final List<SoftwareVersion> localVersions = (local != null && local.getVersions() != null) ? local.getVersions() : new ArrayList<SoftwareVersion>();
    final String args = MessageFormat.format("Number of local versions/maximum software versions allowed: [{0}/{1}] current version: {2} local versions: {3} ", localVersions.size(), MAX_SOFTWARE_VERSIONS, localCurrent, Strings.repr(localVersions));
    final String prefix = "getUpgradeableRemoteVersions(): " + args + " : ";
    log.info("Getting remote new versions: " + prefix);
    List<SoftwareVersion> tempList = new ArrayList<SoftwareVersion>();
    List<SoftwareVersion> toInstallCandidates = new ArrayList<SoftwareVersion>(remoteVersions.keySet());
    Collections.sort(toInstallCandidates);
    Collections.reverse(toInstallCandidates);
    log.debug("Test if a version is upgradeable");
    ToInstallLoop: for (SoftwareVersion toInstall : toInstallCandidates) {
        log.debug(" try=" + toInstall);
        // skip version lower than current version
        if (!forceInstall && localCurrent.compareTo(toInstall) > 0) {
            log.debug(" try=" + toInstall + ": lower than or equal to existing. Skipping.");
            continue;
        }
        // skip local versions
        for (SoftwareVersion version : localVersions) {
            if (version.compareTo(toInstall) == 0) {
                log.debug(" try=" + toInstall + ": already downloaded {}. Skipping.", version);
                continue ToInstallLoop;
            }
        }
        if (localCurrent.isNaturallySwitchableTo(toInstall)) {
            tempList.add(toInstall);
            continue;
        }
        for (SoftwareVersion v : remoteVersions.get(toInstall)) {
            for (SoftwareVersion s : localVersions) {
                if (v.weakEquals(s)) {
                    log.debug(" try=" + toInstall + ": can be ungraded from one of the local versions, it's upgradeable.");
                    tempList.add(toInstall);
                    continue ToInstallLoop;
                }
            }
        }
    }
    return tempList;
}
Also used : SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion)

Aggregations

SoftwareVersion (com.emc.storageos.coordinator.client.model.SoftwareVersion)44 RepositoryInfo (com.emc.storageos.coordinator.client.model.RepositoryInfo)12 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)10 InvalidSoftwareVersionException (com.emc.storageos.coordinator.exceptions.InvalidSoftwareVersionException)9 RemoteRepositoryException (com.emc.storageos.systemservices.exceptions.RemoteRepositoryException)9 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 Path (javax.ws.rs.Path)8 LocalRepositoryException (com.emc.storageos.systemservices.exceptions.LocalRepositoryException)7 IOException (java.io.IOException)7 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)6 ServiceUnavailableException (com.emc.storageos.svcs.errorhandling.resources.ServiceUnavailableException)6 CoordinatorClientException (com.emc.storageos.systemservices.exceptions.CoordinatorClientException)6 ClusterInfo (com.emc.vipr.model.sys.ClusterInfo)5 File (java.io.File)5 Produces (javax.ws.rs.Produces)5 InputStream (java.io.InputStream)4 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)3 POST (javax.ws.rs.POST)3 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3