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);
}
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;
}
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"));
}
}
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());
}
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());
}
Aggregations