Search in sources :

Example 1 with RemoteRepositoryException

use of com.emc.storageos.systemservices.exceptions.RemoteRepositoryException in project coprhd-controller by CoprHD.

the class UpgradeService method installImage.

/**
 * Install image. Image can be installed only if the number of installed images are less than MAX_SOFTWARE_VERSIONS
 *
 * @brief Install image
 * @param versionStr Version to be installed
 * @prereq Cluster state should be STABLE
 * @return Cluster state information
 * @throws Exception
 */
@POST
@Path("image/install/")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public Response installImage(@QueryParam("version") String versionStr) throws Exception {
    _log.info("installImage({})", versionStr);
    final SoftwareVersion version;
    try {
        version = new SoftwareVersion(versionStr);
    } catch (InvalidSoftwareVersionException e) {
        throw APIException.badRequests.parameterIsNotValid("version");
    }
    // do not proceed if there's paused sites.
    checkClusterState(false);
    RepositoryInfo repoInfo = null;
    try {
        repoInfo = _coordinator.getTargetInfo(RepositoryInfo.class);
    } catch (Exception e) {
        throw APIException.internalServerErrors.getObjectFromError("target repository info", "coordinator", e);
    }
    SoftwareVersion currentVersion = repoInfo.getCurrentVersion();
    List<SoftwareVersion> localAvailableVersions = repoInfo.getVersions();
    if (localAvailableVersions.size() > SyncInfoBuilder.MAX_SOFTWARE_VERSIONS) {
        throw APIException.badRequests.numberOfInstalledExceedsMax();
    }
    RemoteRepository repo = _upgradeManager.getRemoteRepository();
    if (isInstalled(repoInfo.getVersions(), version)) {
        throw APIException.badRequests.versionIsInstalled(versionStr);
    }
    if (!isUpgradable(repoInfo.getCurrentVersion(), version)) {
        throw APIException.badRequests.versionIsNotAvailableForUpgrade(versionStr);
    }
    try {
        // check that the version can be downloaded from the remote repository
        repo.checkVersionDownloadable(version);
    } catch (RemoteRepositoryException e) {
        throw APIException.internalServerErrors.getObjectError("remote repository info", e);
    }
    List<SoftwareVersion> newList = new ArrayList<SoftwareVersion>(localAvailableVersions);
    newList.add(version);
    int versionSize = repo.checkVersionSize(version);
    _log.info("The size of the image is:" + versionSize);
    initializeDownloadProgress(versionStr, versionSize);
    try {
        _coordinator.setTargetInfo(new RepositoryInfo(currentVersion, newList));
    } catch (Exception e) {
        throw APIException.internalServerErrors.setObjectToError("target versions", "coordinator", e);
    }
    auditUpgrade(OperationTypeEnum.INSTALL_IMAGE, AuditLogManager.AUDITLOG_SUCCESS, null, versionStr);
    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) RemoteRepositoryException(com.emc.storageos.systemservices.exceptions.RemoteRepositoryException) 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 2 with RemoteRepositoryException

use of com.emc.storageos.systemservices.exceptions.RemoteRepositoryException in project coprhd-controller by CoprHD.

the class RemoteRepositoryTest method startBackgroundDownload.

private File startBackgroundDownload(final SoftwareVersion version) {
    final File file = new File(DOWNLOAD_DIR + '/' + version + SOFTWARE_IMAGE_SUFFIX);
    final String prefix = MessageFormat.format("startBackGroundDownload(): version={0} path=\"{1}\": ", version, file);
    InputStream in;
    URL url;
    try {
        url = _repo.getImageURL(version);
        in = _repo.getImageInputStream(url);
    } catch (RemoteRepositoryException e) {
        System.out.println(prefix + e);
        return null;
    }
    System.out.println(prefix + "Starting backgroud download.");
    _downloader.startBackgroundDownload(prefix, file, in, url.toString(), version.toString());
    return file;
}
Also used : InputStream(java.io.InputStream) RemoteRepositoryException(com.emc.storageos.systemservices.exceptions.RemoteRepositoryException) File(java.io.File) URL(java.net.URL)

Example 3 with RemoteRepositoryException

use of com.emc.storageos.systemservices.exceptions.RemoteRepositoryException in project coprhd-controller by CoprHD.

the class RemoteRepositoryTest method testBadCredentials.

@Test
public void testBadCredentials() throws Exception {
    repositoryUrl = CATALOG_SERVER_URL;
    repositoryProxy = null;
    username = USERNAME;
    _repo = RemoteRepository.getInstance();
    final List<SoftwareVersion> remoteVersions = _repo.getVersions();
    Assert.assertTrue(remoteVersions != null);
    Assert.assertTrue(!remoteVersions.isEmpty());
    SoftwareVersion v = remoteVersions.get(0);
    // NOSONAR ("squid:S2068 Suppressing sonar violation of hard-coded password")
    password = "badpassword";
    _repo = RemoteRepository.getInstance();
    try {
        _repo.checkVersionDownloadable(remoteVersions.get(0));
    } catch (RemoteRepositoryException e) {
        Assert.assertTrue(e.getMessage().contains("Log in to") && e.getMessage().contains("failed"));
    }
}
Also used : SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion) RemoteRepositoryException(com.emc.storageos.systemservices.exceptions.RemoteRepositoryException) Test(org.junit.Test)

Example 4 with RemoteRepositoryException

use of com.emc.storageos.systemservices.exceptions.RemoteRepositoryException in project coprhd-controller by CoprHD.

the class RemoteRepositoryTest method testDirectoryRepository.

@Test
public void testDirectoryRepository() throws Exception {
    repositoryUrl = DIRECTORY_REPO;
    _repo = RemoteRepository.getInstance();
    Assert.assertTrue(_repo != null);
    final List<SoftwareVersion> remoteVersions = _repo.getVersions();
    Assert.assertTrue(remoteVersions != null);
    Assert.assertTrue(!remoteVersions.isEmpty());
    for (SoftwareVersion v : remoteVersions) {
        System.out.println(v);
    }
    int downloadableVersions = 0;
    for (SoftwareVersion v : remoteVersions) {
        try {
            _repo.checkVersionDownloadable(v);
        } catch (RemoteRepositoryException e) {
            continue;
        } catch (BadRequestException e) {
            continue;
        }
        final InputStream in = _repo.getImageInputStream(v);
        Assert.assertTrue(in != null);
        byte[] buffer = new byte[0x10000];
        Assert.assertTrue("getImageInputStream failed for " + v, in.read(buffer) > 0);
        in.close();
        downloadableVersions++;
    }
    // Make sure there are at least some downloadable versiosn
    Assert.assertTrue(downloadableVersions > 0);
    System.out.println("Found " + downloadableVersions + " downloadable versions out of " + remoteVersions.size());
    final SoftwareVersion version = (SoftwareVersion) remoteVersions.toArray()[0];
    File file = startBackgroundDownload(version);
    Assert.assertNotNull(file);
    while (_downloader.isDownloading()) {
        System.out.println("Downloading " + file);
        Thread.sleep(2000);
    }
    Assert.assertTrue(file.exists());
}
Also used : SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion) InputStream(java.io.InputStream) RemoteRepositoryException(com.emc.storageos.systemservices.exceptions.RemoteRepositoryException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) File(java.io.File) Test(org.junit.Test)

Example 5 with RemoteRepositoryException

use of com.emc.storageos.systemservices.exceptions.RemoteRepositoryException in project coprhd-controller by CoprHD.

the class RemoteRepositoryTest method testCatalogRepository.

@Test
public void testCatalogRepository() throws Exception {
    repositoryUrl = CATALOG_SERVER_URL;
    _repo = RemoteRepository.getInstance();
    Assert.assertTrue(_repo != null);
    final List<SoftwareVersion> remoteVersions = _repo.getVersions();
    Assert.assertTrue(remoteVersions != null);
    Assert.assertTrue(!remoteVersions.isEmpty());
    for (SoftwareVersion v : remoteVersions) {
        System.out.println(v);
    }
    int downloadableVersions = 0;
    for (SoftwareVersion v : remoteVersions) {
        try {
            _repo.checkVersionDownloadable(v);
        } catch (RemoteRepositoryException e) {
            continue;
        } catch (BadRequestException e) {
            continue;
        }
        final InputStream in = _repo.getImageInputStream(v);
        Assert.assertTrue(in != null);
        byte[] buffer = new byte[0x10000];
        Assert.assertTrue("getImageInputStream failed for " + v, in.read(buffer) > 0);
        in.close();
        downloadableVersions++;
    }
    // Make sure there are at least some downloadable versiosn
    Assert.assertTrue(downloadableVersions > 0);
    System.out.println("Found " + downloadableVersions + " downloadable versions out of " + remoteVersions.size());
    SoftwareVersion version = null;
    // avoid version 121 since it is bad
    for (SoftwareVersion remoteVersion : remoteVersions) {
        // / Avoid a specific version on the downloads test site because it is no good
        if (0 != remoteVersion.compareTo(new SoftwareVersion("vipr-1.0.0.7.121"))) {
            version = remoteVersion;
            break;
        }
    }
    Assert.assertNotNull(version);
    File file = startBackgroundDownload(version);
    Assert.assertNotNull(file);
    while (_downloader.isDownloading()) {
        System.out.println("Downloading " + file);
        Thread.sleep(2000);
    }
    Assert.assertTrue(file.exists());
}
Also used : SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion) InputStream(java.io.InputStream) RemoteRepositoryException(com.emc.storageos.systemservices.exceptions.RemoteRepositoryException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) File(java.io.File) Test(org.junit.Test)

Aggregations

RemoteRepositoryException (com.emc.storageos.systemservices.exceptions.RemoteRepositoryException)5 SoftwareVersion (com.emc.storageos.coordinator.client.model.SoftwareVersion)4 File (java.io.File)3 InputStream (java.io.InputStream)3 Test (org.junit.Test)3 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)2 RepositoryInfo (com.emc.storageos.coordinator.client.model.RepositoryInfo)1 InvalidSoftwareVersionException (com.emc.storageos.coordinator.exceptions.InvalidSoftwareVersionException)1 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 ServiceUnavailableException (com.emc.storageos.svcs.errorhandling.resources.ServiceUnavailableException)1 CoordinatorClientException (com.emc.storageos.systemservices.exceptions.CoordinatorClientException)1 LocalRepositoryException (com.emc.storageos.systemservices.exceptions.LocalRepositoryException)1 ClusterInfo (com.emc.vipr.model.sys.ClusterInfo)1 IOException (java.io.IOException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1