Search in sources :

Example 6 with SoftwareVersion

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

the class UpgradeService method setTargetVersion.

/**
 * Upgrade target version. Refer to product documentation for valid upgrade paths.
 *
 * @brief Update the target version of the build
 * @param version The new version number
 * @prereq Target version should be installed and cluster state should be STABLE
 * @return Cluster state information.
 * @throws IOException
 */
@PUT
@Path("target-version/")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public Response setTargetVersion(@QueryParam("version") String version, @QueryParam("force") String forceUpgrade) throws IOException {
    SoftwareVersion targetVersion = null;
    try {
        targetVersion = new SoftwareVersion(version);
    } catch (InvalidSoftwareVersionException e) {
        throw APIException.badRequests.parameterIsNotValid("version");
    }
    // validate
    if (!_coordinator.isClusterUpgradable()) {
        throw APIException.serviceUnavailable.clusterStateNotStable();
    }
    if (!_coordinator.isAllDatabaseServiceUp()) {
        throw APIException.serviceUnavailable.databaseServiceNotAllUp();
    }
    // check if all DR sites are in stable or paused status
    checkClusterState(true);
    List<SoftwareVersion> available = null;
    try {
        available = _coordinator.getVersions(_coordinator.getMySvcId());
    } catch (CoordinatorClientException e) {
        throw APIException.internalServerErrors.getObjectFromError("available versions", "coordinator", e);
    }
    if (!available.contains(targetVersion)) {
        throw APIException.badRequests.versionIsNotAvailableForUpgrade(version);
    }
    // To Do - add a check for upgradable from current
    SoftwareVersion current = null;
    try {
        current = _coordinator.getRepositoryInfo(_coordinator.getMySvcId()).getCurrentVersion();
    } catch (CoordinatorClientException e) {
        throw APIException.internalServerErrors.getObjectFromError("current version", "coordinator", e);
    }
    if (!current.isSwitchableTo(targetVersion)) {
        throw APIException.badRequests.versionIsNotUpgradable(targetVersion.toString(), current.toString());
    }
    // Check if allowed from upgrade voter and force option can veto
    if (FORCE.equals(forceUpgrade)) {
        _log.info("Force option supplied, skipping all geo/dr pre-checks");
    } else {
        for (UpgradeVoter voter : _upgradeVoters) {
            voter.isOKForUpgrade(current.toString(), version);
        }
    }
    try {
        _coordinator.setTargetInfo(new RepositoryInfo(targetVersion, _coordinator.getTargetInfo(RepositoryInfo.class).getVersions()));
    } catch (Exception e) {
        throw APIException.internalServerErrors.setObjectToError("target version", "coordinator", e);
    }
    _log.info("target version changed successfully. new target {}", targetVersion);
    auditUpgrade(OperationTypeEnum.UPDATE_VERSION, AuditLogManager.AUDITLOG_SUCCESS, null, targetVersion.toString(), FORCE.equals(forceUpgrade));
    ClusterInfo clusterInfo = _coordinator.getClusterInfo();
    if (clusterInfo == null) {
        throw APIException.internalServerErrors.targetIsNullOrEmpty("Cluster info");
    }
    return toClusterResponse(clusterInfo);
}
Also used : InvalidSoftwareVersionException(com.emc.storageos.coordinator.exceptions.InvalidSoftwareVersionException) ClusterInfo(com.emc.vipr.model.sys.ClusterInfo) SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion) RepositoryInfo(com.emc.storageos.coordinator.client.model.RepositoryInfo) UpgradeVoter(com.emc.storageos.security.upgradevoter.UpgradeVoter) CoordinatorClientException(com.emc.storageos.systemservices.exceptions.CoordinatorClientException) RemoteRepositoryException(com.emc.storageos.systemservices.exceptions.RemoteRepositoryException) ServiceUnavailableException(com.emc.storageos.svcs.errorhandling.resources.ServiceUnavailableException) InvalidSoftwareVersionException(com.emc.storageos.coordinator.exceptions.InvalidSoftwareVersionException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) LocalRepositoryException(com.emc.storageos.systemservices.exceptions.LocalRepositoryException) IOException(java.io.IOException) CoordinatorClientException(com.emc.storageos.systemservices.exceptions.CoordinatorClientException) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 7 with SoftwareVersion

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

the class UpgradeService method removeImage.

/**
 * Remove an image. Image can be removed only if the number of installed images are
 * greater than MAX_SOFTWARE_VERSIONS
 *
 * @brief Remove an image
 * @param versionStr Version to be removed
 * @param forceRemove If force=1, image will be removed even if the maximum number of versions installed are less than
 *            MAX_SOFTWARE_VERSIONS
 * @prereq Image should be installed and cluster state should be STABLE
 * @return Cluster state information
 * @throws IOException
 */
@POST
@Path("image/remove/")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public Response removeImage(@QueryParam("version") String versionStr, @QueryParam("force") String forceRemove) throws IOException {
    _log.info("removeImage({})", versionStr);
    final SoftwareVersion version;
    try {
        version = new SoftwareVersion(versionStr);
    } catch (InvalidSoftwareVersionException e) {
        throw APIException.badRequests.parameterIsNotValid("version");
    }
    RepositoryInfo targetInfo = null;
    try {
        targetInfo = _coordinator.getTargetInfo(RepositoryInfo.class);
    } catch (Exception e) {
        throw APIException.internalServerErrors.getObjectFromError("target repository info", "coordinator", e);
    }
    final SyncInfo remoteSyncInfo = SyncInfoBuilder.removableVersions(targetInfo, FORCE.equals(forceRemove));
    if (remoteSyncInfo.isEmpty() || remoteSyncInfo.getToRemove() == null || !remoteSyncInfo.getToRemove().contains(version)) {
        throw APIException.badRequests.versionIsNotRemovable(versionStr);
    }
    List<SoftwareVersion> newList = new ArrayList<SoftwareVersion>(targetInfo.getVersions());
    newList.remove(version);
    try {
        _coordinator.setTargetInfo(new RepositoryInfo(targetInfo.getCurrentVersion(), newList), !FORCE.equals(forceRemove));
    } catch (Exception e) {
        throw APIException.internalServerErrors.setObjectToError("target versions", "coordinator", e);
    }
    auditUpgrade(OperationTypeEnum.REMOVE_IMAGE, AuditLogManager.AUDITLOG_SUCCESS, null, versionStr, FORCE.equals(forceRemove));
    ClusterInfo clusterInfo = _coordinator.getClusterInfo();
    if (clusterInfo == null) {
        throw APIException.internalServerErrors.targetIsNullOrEmpty("Cluster info");
    }
    return toClusterResponse(clusterInfo);
}
Also used : InvalidSoftwareVersionException(com.emc.storageos.coordinator.exceptions.InvalidSoftwareVersionException) ClusterInfo(com.emc.vipr.model.sys.ClusterInfo) SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion) RepositoryInfo(com.emc.storageos.coordinator.client.model.RepositoryInfo) ArrayList(java.util.ArrayList) RemoteRepositoryException(com.emc.storageos.systemservices.exceptions.RemoteRepositoryException) ServiceUnavailableException(com.emc.storageos.svcs.errorhandling.resources.ServiceUnavailableException) InvalidSoftwareVersionException(com.emc.storageos.coordinator.exceptions.InvalidSoftwareVersionException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) LocalRepositoryException(com.emc.storageos.systemservices.exceptions.LocalRepositoryException) IOException(java.io.IOException) CoordinatorClientException(com.emc.storageos.systemservices.exceptions.CoordinatorClientException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 8 with SoftwareVersion

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

the class LocalRepository method getRepositoryInfo.

/**
 * @return RepositoryState
 * @throws InvalidRepositoryInfoException
 */
public RepositoryInfo getRepositoryInfo() throws LocalRepositoryException, InvalidRepositoryInfoException {
    final String prefix = "getRepositoryState(): ";
    _log.debug(prefix);
    final String[] cmd1 = { _SYSTOOL_CMD, _SYSTOOL_LIST };
    List<SoftwareVersion> versions = toSoftwareVersionList(prefix + _SYSTOOL_LIST, exec(prefix, cmd1));
    final String[] cmd2 = { _SYSTOOL_CMD, _SYSTOOL_GET_DEFAULT };
    final SoftwareVersion current = toSoftwareVersionList(prefix + _SYSTOOL_GET_DEFAULT, exec(prefix, cmd2)).get(0);
    _log.debug(prefix + "current={} versions={}", current, Strings.repr(versions));
    return new RepositoryInfo(current, versions);
}
Also used : SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion) RepositoryInfo(com.emc.storageos.coordinator.client.model.RepositoryInfo)

Example 9 with SoftwareVersion

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

the class RemoteRepository method parseCatalog.

/**
 * Parse the EMC software update string representation
 *
 * @param input the EMC software catalog string representation
 * @return a map of software version to remote file URLs
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws IOException
 * @throws XPathExpressionException
 * @throws InvalidSoftwareVersionException
 * @throws MalformedURLException
 * @throws RemoteRepositoryException
 */
private Map<SoftwareVersion, URL> parseCatalog(String input) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException, InvalidSoftwareVersionException, MalformedURLException, RemoteRepositoryException {
    Map<SoftwareVersion, URL> versions = new HashMap<SoftwareVersion, URL>();
    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);
    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, "");
                Node urlNode = element.getAttributeNode("URL");
                String fileUrl = urlNode.getNodeValue();
                versions.put(new SoftwareVersion(fileVersion), new URL(fileUrl));
            }
        }
    }
    if (versions.isEmpty()) {
        throw SyssvcException.syssvcExceptions.remoteRepoError("Empty remote repository: " + _repo);
    }
    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 10 with SoftwareVersion

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

the class RemoteRepository method getVersionsWithMetadataCatalog.

private Map<SoftwareVersion, List<SoftwareVersion>> getVersionsWithMetadataCatalog(String catalogString) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException, InvalidSoftwareVersionException, MalformedURLException, RemoteRepositoryException {
    Map<SoftwareVersion, List<SoftwareVersion>> map = new HashMap<SoftwareVersion, List<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);
    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, "");
                Node catalogInfoNode = element.getAttributeNode("CatalogInfo");
                String catalogInfo = catalogInfoNode.getNodeValue();
                SoftwareVersion tempVersion = new SoftwareVersion(fileVersion);
                List<SoftwareVersion> tempList = new ArrayList<SoftwareVersion>();
                if (!catalogInfo.equals("")) {
                    String upgradeFromInfoRaw = null;
                    for (String s : catalogInfo.split(",")) {
                        // key-value pairs are separated by comma
                        if (s.startsWith("upgradeFromVersions=")) {
                            upgradeFromInfoRaw = s;
                            break;
                        }
                    }
                    // only need the value
                    String upgradeFromInfo = upgradeFromInfoRaw.split("=")[1];
                    for (String versionStr : upgradeFromInfo.split(";")) {
                        // versions are separated by semicolon
                        tempList.add(new SoftwareVersion(versionStr));
                    }
                }
                map.put(tempVersion, tempList);
            }
        }
    }
    return map;
}
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)

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