use of com.emc.storageos.coordinator.client.model.RepositoryInfo in project coprhd-controller by CoprHD.
the class ConfigService method getProperties.
/**
* Get system configuration properties
*
* @brief Get system properties
* @prereq none
* @param category - type of properties to return: all, config, ovf, mutated, secrets (require SecurityAdmin role)
* or obsolete
* @return Properties Information if success. Error response, if error./**
*/
@GET
@Path("properties/")
@CheckPermission(roles = { Role.SECURITY_ADMIN, Role.SYSTEM_MONITOR })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public PropertyInfoRestRep getProperties(@DefaultValue("all") @QueryParam("category") String category) throws Exception {
switch(PropCategory.valueOf(category.toUpperCase())) {
case ALL:
return getTargetPropsCommon();
case CONFIG:
return new PropertyInfoRestRep(getConfigProperties());
case OVF:
return new PropertyInfoRestRep(getPropertiesOvf());
case REDEPLOY:
Map<String, String> props = getPropertiesOvf();
props.remove(MODE);
props.remove(NODE_ID);
Map<String, String> clusterInfo = new HashMap();
Set<Map.Entry<String, String>> ovfProps = props.entrySet();
for (Map.Entry<String, String> ovfProp : ovfProps) {
String parameter = propertyToParameters.get(ovfProp.getKey());
if (parameter == null) {
continue;
}
clusterInfo.put(parameter, ovfProp.getValue());
}
// Add ipsec key
clusterInfo.put(IPSEC_KEY, ipsecConfig.getPreSharedKey());
// Add version info
RepositoryInfo info = _coordinator.getTargetInfo(RepositoryInfo.class);
clusterInfo.put(VERSION, info.getCurrentVersion().toString());
_log.info("clusterInfo={}", clusterInfo);
return new PropertyInfoRestRep(clusterInfo);
case MUTATED:
return new PropertyInfoRestRep(getMutatedProps());
case SECRETS:
StorageOSUser user = getUserFromContext();
if (!user.getRoles().contains(Role.SECURITY_ADMIN.toString())) {
throw APIException.forbidden.onlySecurityAdminsCanGetSecrets();
}
return getTargetPropsCommon(false);
case OBSOLETE:
return new PropertyInfoRestRep(getObsoleteProperties());
default:
throw APIException.badRequests.invalidParameter("category", category);
}
}
use of com.emc.storageos.coordinator.client.model.RepositoryInfo in project coprhd-controller by CoprHD.
the class UpgradeService method uploadImage.
/**
* Upload the image file given.
* Consumes MediaType.APPLICATION_OCTET_STREAM.
* This is an asynchronous operation.
*
* @brief Upload the specified image file
* @prereq Cluster state should be STABLE
* @return Cluster information.
*/
@POST
@Path("image/upload")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
@Consumes({ MediaType.APPLICATION_OCTET_STREAM })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response uploadImage(@Context HttpServletRequest request) {
File file = null;
String svcId = _coordinator.getMySvcId();
_log.info("uploadImage to {} start", svcId);
// validate
if (!_coordinator.isClusterUpgradable()) {
throw APIException.serviceUnavailable.clusterStateNotStable();
}
// maximal install number check
RepositoryInfo targetInfo = null;
try {
targetInfo = _coordinator.getTargetInfo(RepositoryInfo.class);
} catch (Exception e) {
throw APIException.internalServerErrors.getObjectFromError("target repository info", "coordinator", e);
}
if (targetInfo.getVersions().size() > SyncInfoBuilder.MAX_SOFTWARE_VERSIONS) {
throw APIException.badRequests.numberOfInstalledExceedsMax();
}
// length check
String contentLength = request.getHeader("Content-Length");
if (Long.parseLong(contentLength) <= 0 || Long.parseLong(contentLength) > MAX_UPLOAD_SIZE) {
throw APIException.badRequests.fileSizeExceedsLimit(MAX_UPLOAD_SIZE);
}
try {
// remove previous and upload to a temp file
UpgradeImageUploader uploader = UpgradeImageUploader.getInstance(_upgradeManager);
uploader.cleanUploadFiles();
long versionSize = Long.valueOf(contentLength);
_log.info("The size of the image is:" + versionSize);
String version = VIPR_UNKNOWN_IMAGE_VERSION;
initializeDownloadProgress(version, versionSize);
file = uploader.startUpload(request.getInputStream(), version);
// install image
if (file == null || file != null && !file.exists()) {
throw APIException.internalServerErrors.targetIsNullOrEmpty("Uploaded file");
}
version = _upgradeManager.getLocalRepository().installImage(file);
// set target
List<SoftwareVersion> newList = new ArrayList<SoftwareVersion>(targetInfo.getVersions());
SoftwareVersion newVersion = new SoftwareVersion(version);
if (newList.contains(newVersion)) {
_log.info("Version has already been installed");
} else {
newList.add(newVersion);
_coordinator.setTargetInfo(new RepositoryInfo(targetInfo.getCurrentVersion(), newList));
DownloadingInfo temp = _coordinator.getNodeGlobalScopeInfo(DownloadingInfo.class, DOWNLOADINFO_KIND, svcId);
_coordinator.setNodeGlobalScopeInfo(new DownloadingInfo(version, versionSize, versionSize, DownloadStatus.COMPLETED, temp._errorCounter), DOWNLOADINFO_KIND, svcId);
_coordinator.setTargetInfo(new DownloadingInfo(version, versionSize), false);
}
_log.info("uploadImage to {} end", svcId);
auditUpgrade(OperationTypeEnum.UPLOAD_IMAGE, AuditLogManager.AUDITLOG_SUCCESS, null, targetInfo.getCurrentVersion().toString(), svcId);
// return cluster status
ClusterInfo clusterInfo = _coordinator.getClusterInfo();
if (clusterInfo == null) {
throw APIException.internalServerErrors.targetIsNullOrEmpty("Cluster info");
}
return toClusterResponse(clusterInfo);
} catch (APIException ae) {
throw ae;
} catch (Exception e) {
throw APIException.internalServerErrors.uploadInstallError(e);
} finally {
if (file != null && file.exists()) {
file.delete();
}
}
}
use of com.emc.storageos.coordinator.client.model.RepositoryInfo in project coprhd-controller by CoprHD.
the class LocalRepositoryTest method localRepositoryTest.
@Test
public void localRepositoryTest() throws Exception {
// getVersions() returns an empty List but never null
LocalRepository _localRepo = LocalRepository.getInstance();
RepositoryInfo state = _localRepo.getRepositoryInfo();
SoftwareVersion current = state.getCurrentVersion();
Assert.assertNotNull(current);
System.out.println("current=" + current);
List<SoftwareVersion> available = state.getVersions();
Assert.assertNotNull(available);
System.out.println("available=");
byte[] buf = new byte[100];
for (SoftwareVersion v : available) {
System.out.println(v);
InputStream in = _localRepo.getImageInputStream(v);
try {
Assert.assertTrue(in.read(buf) == buf.length);
} finally {
in.close();
}
}
}
use of com.emc.storageos.coordinator.client.model.RepositoryInfo in project coprhd-controller by CoprHD.
the class SyncInfoTest method testLocal.
@Test
public void testLocal() throws Exception {
// NOSONAR
new TestProductName();
// ("squid:S1848 Suppress Sonar warning that created objects are never used. The constructor is called to set static fields")
// tests getLeaderSyncInfo
List<SoftwareVersion> localVersions = arrayToList(new String[] { "vipr-1.0.0.0.r500", "vipr-1.0.0.0.r555", "vipr-1.0.0.1.r500" });
List<SoftwareVersion> remoteVersions = arrayToList(new String[] { "vipr-1.0.0.2.r500", "vipr-1.0.0.0.r555", "vipr-1.0.0.1.r500" });
// invalid args
RepositoryInfo localState = new RepositoryInfo(new SoftwareVersion("vipr-1.0.0.1.r500"), remoteVersions);
RepositoryInfo remoteState = new RepositoryInfo(new SoftwareVersion("vipr-1.0.0.1.r500"), remoteVersions);
Assert.assertTrue(SyncInfoBuilder.getTargetSyncInfo(localState, remoteState).isEmpty());
// test -1 - add 1, nothing to remove
remoteState = new RepositoryInfo(new SoftwareVersion("vipr-1.0.0.0.r555"), remoteVersions);
localState = new RepositoryInfo(new SoftwareVersion("vipr-1.0.0.0.r500"), localVersions);
SyncInfo syncInfo = SyncInfoBuilder.getTargetSyncInfo(localState, remoteState);
Assert.assertTrue(syncInfo.getToRemove().isEmpty());
Assert.assertEquals(arrayToList(new String[] { "vipr-1.0.0.2.r500" }), syncInfo.getToInstall());
// test 2 - sync 1, remove 1
localVersions = arrayToList(new String[] { "vipr-1.0.0.0.r500", "vipr-1.0.0.0.r555", "vipr-1.0.0.1.r500" });
remoteVersions = arrayToList(new String[] { "vipr-1.0.0.1.r555", "vipr-1.0.0.0.r555", "vipr-1.0.0.1.r500" });
remoteState = new RepositoryInfo(new SoftwareVersion("vipr-1.0.0.1.r500"), remoteVersions);
localState = new RepositoryInfo(new SoftwareVersion("vipr-1.0.0.0.r555"), localVersions);
verifyEqual(SyncInfoBuilder.getTargetSyncInfo(localState, remoteState), "vipr-1.0.0.1.r555", new String[] {});
// test 3 - sync to remote current
// phase - 1
localVersions = arrayToList(new String[] { "vipr-1.0.0.0.r500", "vipr-1.0.0.0.r555", "vipr-1.0.0.1.r500" });
remoteVersions = arrayToList(new String[] { "vipr-1.0.0.2.r555", "vipr-1.0.0.1.r500", "vipr-1.0.0.2.r500" });
remoteState = new RepositoryInfo(new SoftwareVersion("vipr-1.0.0.2.r555"), remoteVersions);
localState = new RepositoryInfo(new SoftwareVersion("vipr-1.0.0.1.r500"), localVersions);
verifyEqual(SyncInfoBuilder.getTargetSyncInfo(localState, remoteState), "vipr-1.0.0.2.r500", new String[] {});
// phase 2
localVersions = arrayToList(new String[] { "vipr-1.0.0.2.r500", "vipr-1.0.0.0.r555", "vipr-1.0.0.1.r500" });
remoteVersions = arrayToList(new String[] { "vipr-1.0.0.2.r555", "vipr-1.0.0.1.r500", "vipr-1.0.0.2.r500" });
remoteState = new RepositoryInfo(new SoftwareVersion("vipr-1.0.0.2.r555"), remoteVersions);
localState = new RepositoryInfo(new SoftwareVersion("vipr-1.0.0.1.r500"), localVersions);
verifyEqual(SyncInfoBuilder.getTargetSyncInfo(localState, remoteState), "vipr-1.0.0.2.r555", new String[] {});
// test 4 - complete disjoint , upgradable
// phase 1
localVersions = arrayToList(new String[] { "vipr-1.0.0.0.r500", "vipr-1.0.0.0.r555", "vipr-1.0.0.0.r600" });
remoteVersions = arrayToList(new String[] { "vipr-1.0.0.0.r700", "vipr-1.0.0.0.r750", "vipr-1.0.0.0.r800" });
remoteState = new RepositoryInfo(new SoftwareVersion("vipr-1.0.0.0.r800"), remoteVersions);
localState = new RepositoryInfo(new SoftwareVersion("vipr-1.0.0.0.r500"), localVersions);
verifyEqual(SyncInfoBuilder.getTargetSyncInfo(localState, remoteState), "vipr-1.0.0.0.r700", new String[] {});
// phase 2
localVersions = arrayToList(new String[] { "vipr-1.0.0.0.r500", "vipr-1.0.0.0.r700", "vipr-1.0.0.0.r600" });
remoteVersions = arrayToList(new String[] { "vipr-1.0.0.0.r700", "vipr-1.0.0.0.r750", "vipr-1.0.0.0.r800" });
remoteState = new RepositoryInfo(new SoftwareVersion("vipr-1.0.0.0.r800"), remoteVersions);
localState = new RepositoryInfo(new SoftwareVersion("vipr-1.0.0.0.r500"), localVersions);
verifyEqual(SyncInfoBuilder.getTargetSyncInfo(localState, remoteState), "vipr-1.0.0.0.r750", new String[] {});
// phase 3 - nothing to do - no-deletable
localVersions = arrayToList(new String[] { "vipr-1.0.0.0.r500", "vipr-1.0.0.0.r700", "vipr-1.0.0.0.r750" });
remoteVersions = arrayToList(new String[] { "vipr-1.0.0.0.r700", "vipr-1.0.0.0.r750", "vipr-1.0.0.0.r800" });
remoteState = new RepositoryInfo(new SoftwareVersion("vipr-1.0.0.0.r800"), remoteVersions);
localState = new RepositoryInfo(new SoftwareVersion("vipr-1.0.0.0.r500"), localVersions);
verifyEqual(SyncInfoBuilder.getTargetSyncInfo(localState, remoteState), "vipr-1.0.0.0.r800", new String[] {});
}
use of com.emc.storageos.coordinator.client.model.RepositoryInfo in project coprhd-controller by CoprHD.
the class DisasterRecoveryServiceTest method setUp.
@Before
public void setUp() throws Exception {
Constructor constructor = ProductName.class.getDeclaredConstructors()[0];
constructor.setAccessible(true);
ProductName productName = (ProductName) constructor.newInstance();
productName.setName("vipr");
SoftwareVersion version = new SoftwareVersion("vipr-2.4.0.0.100");
LinkedList<SoftwareVersion> available = new LinkedList<SoftwareVersion>();
available.add(version);
RepositoryInfo repositoryInfo = new RepositoryInfo(new SoftwareVersion("vipr-2.4.0.0.100"), available);
standby = new SiteConfigRestRep();
standby.setClusterStable(true);
standby.setFreshInstallation(true);
standby.setDbSchemaVersion("2.4");
standby.setSoftwareVersion("vipr-2.4.0.0.150");
standby.setHostIPv4AddressMap(new HashMap<String, String>());
standby.getHostIPv4AddressMap().put("vipr1", "10.247.101.100");
// setup standby site
standbySite1 = new Site();
standbySite1.setUuid("site-uuid-1");
standbySite1.setVip("10.247.101.110");
standbySite1.getHostIPv4AddressMap().put("vipr1", "10.247.101.111");
standbySite1.getHostIPv4AddressMap().put("vipr2", "10.247.101.112");
standbySite1.getHostIPv4AddressMap().put("vipr3", "10.247.101.113");
standbySite1.setState(SiteState.STANDBY_PAUSED);
standbySite1.setVdcShortId("vdc1");
standbySite1.setNodeCount(1);
standbySite2 = new Site();
standbySite2.setUuid("site-uuid-2");
standbySite2.setState(SiteState.STANDBY_SYNCED);
standbySite2.setVdcShortId("vdc1");
standbySite2.setVip("10.247.101.158");
standbySite2.setNodeCount(1);
standbySite3 = new Site();
standbySite3.setUuid("site-uuid-3");
standbySite3.setVdcShortId("fake-vdc-id");
standbySite3.setState(SiteState.ACTIVE);
standbySite3.setVdcShortId("vdc1");
standbySite3.setNodeCount(1);
primarySite = new Site();
primarySite.setUuid("primary-site-uuid");
primarySite.setVip("127.0.0.1");
primarySite.setHostIPv4AddressMap(standbySite1.getHostIPv4AddressMap());
primarySite.setHostIPv6AddressMap(standbySite1.getHostIPv6AddressMap());
primarySite.setVdcShortId("vdc1");
primarySite.setState(SiteState.ACTIVE);
primarySite.setNodeCount(3);
// mock DBClient
dbClientMock = mock(DbClientImpl.class);
// mock coordinator client
coordinator = mock(CoordinatorClient.class);
// mock ipsecconfig
IPsecConfig ipsecConfig = mock(IPsecConfig.class);
doReturn("ipsec-preshared-key").when(ipsecConfig).getPreSharedKey();
drUtil = mock(DrUtil.class);
natCheckParam = new DRNatCheckParam();
apiSignatureGeneratorMock = mock(InternalApiSignatureKeyGenerator.class);
try {
KeyGenerator keyGenerator = null;
keyGenerator = KeyGenerator.getInstance("HmacSHA256");
secretKey = keyGenerator.generateKey();
} catch (NoSuchAlgorithmException e) {
fail("generate key fail");
}
drService = spy(new DisasterRecoveryService());
drService.setDbClient(dbClientMock);
drService.setCoordinator(coordinator);
drService.setDrUtil(drUtil);
drService.setSiteMapper(new SiteMapper());
drService.setSysUtils(new SysUtils());
drService.setIpsecConfig(ipsecConfig);
drService.setApiSignatureGenerator(apiSignatureGeneratorMock);
standbyConfig = new Site();
standbyConfig.setUuid("standby-site-uuid-1");
standbyConfig.setVip(standbySite1.getVip());
standbyConfig.setHostIPv4AddressMap(standbySite1.getHostIPv4AddressMap());
standbyConfig.setHostIPv6AddressMap(standbySite1.getHostIPv6AddressMap());
standbyConfig.setNodeCount(3);
doReturn(standbyConfig.getUuid()).when(coordinator).getSiteId();
Configuration config = new ConfigurationImpl();
config.setConfig(Constants.CONFIG_DR_ACTIVE_SITEID, primarySite.getUuid());
doReturn(config).when(coordinator).queryConfiguration(Constants.CONFIG_DR_ACTIVE_KIND, Constants.CONFIG_DR_ACTIVE_ID);
doReturn("2.4").when(coordinator).getCurrentDbSchemaVersion();
doReturn(primarySite.getUuid()).when(coordinator).getSiteId();
doReturn(ClusterInfo.ClusterState.STABLE).when(coordinator).getControlNodesState();
// Don't need to record audit log in UT
doNothing().when(drService).auditDisasterRecoveryOps(any(OperationTypeEnum.class), anyString(), anyString(), anyVararg());
doReturn(repositoryInfo).when(coordinator).getTargetInfo(RepositoryInfo.class);
doReturn(standbySite1).when(drUtil).getSiteFromLocalVdc(standbySite1.getUuid());
doReturn(standbySite2).when(drUtil).getSiteFromLocalVdc(standbySite2.getUuid());
doThrow(CoordinatorException.retryables.cannotFindSite(NONEXISTENT_ID)).when(drUtil).getSiteFromLocalVdc(NONEXISTENT_ID);
doReturn(primarySite).when(drUtil).getSiteFromLocalVdc(primarySite.getUuid());
SiteNetworkState siteNetworkState = new SiteNetworkState();
siteNetworkState.setNetworkHealth(SiteNetworkState.NetworkHealth.GOOD);
doReturn(siteNetworkState).when(drUtil).getSiteNetworkState(any(String.class));
CoordinatorClientInetAddressMap addressMap = new CoordinatorClientInetAddressMap();
addressMap.setDualInetAddress(DualInetAddress.fromAddresses("10.247.101.110", ""));
doReturn(addressMap).when(coordinator).getInetAddessLookupMap();
InterProcessLock lock = mock(InterProcessLock.class);
doReturn(lock).when(coordinator).getLock(anyString());
doReturn(true).when(lock).acquire(anyInt(), any(TimeUnit.class));
doNothing().when(lock).release();
}
Aggregations