use of com.emc.storageos.geomodel.VdcConfig in project coprhd-controller by CoprHD.
the class DBClient method loadRecoverFileToRecoverInfo.
/**
* Load the specific recover file to generate newVdcConfigList for recovery
*
* @param recoverFileName
* @return
*/
private List<VdcConfig> loadRecoverFileToRecoverInfo(String recoverFileName) {
List<VdcConfig> newVdcConfigList = new ArrayList<VdcConfig>();
Document doc = null;
try {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
File f = new File(recoverFileName);
BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
DataInputStream dis = new DataInputStream(in);
byte[] loadBytes = new byte[(int) f.length()];
dis.readFully(loadBytes);
String decryptString = geoEncryptionProvider.decrypt(loadBytes);
InputStream decryptStringStream = new ByteArrayInputStream(decryptString.getBytes());
doc = builder.parse(decryptStringStream);
} catch (Exception e) {
System.err.println("Fail to read recover file, if you are not in VDC1 now, " + "please copy the recover file from VDC1 to this VDC and then issue recover command. e= " + e);
throw new RuntimeException("Recover file not found: " + recoverFileName);
}
Element root = doc.getDocumentElement();
NodeList vdcConfigNodes = root.getElementsByTagName("VdcConfig");
for (int i = 0; i < vdcConfigNodes.getLength(); i++) {
Element vdcConfigNode = (Element) vdcConfigNodes.item(i);
VdcConfig newVdcConfig = new VdcConfig();
newVdcConfig.setId(URI.create(vdcConfigNode.getAttribute("id")));
NodeList fields = vdcConfigNode.getElementsByTagName("field");
for (int j = 0; j < fields.getLength(); j++) {
Element field = (Element) fields.item(j);
Method method = null;
try {
if (field.getAttribute("value") == null || field.getAttribute("value").equals("")) {
continue;
}
Class type = Class.forName(field.getAttribute("type"));
method = newVdcConfig.getClass().getMethod("set" + field.getAttribute("name"), type);
if (type == Integer.class) {
method.invoke(newVdcConfig, Integer.valueOf(field.getAttribute("value")));
} else if (type == Long.class) {
method.invoke(newVdcConfig, Long.valueOf(field.getAttribute("value")));
} else if (type == HashMap.class) {
String loadString = field.getAttribute("value").replaceAll("[{}]", "");
if (loadString.equals("")) {
continue;
}
HashMap<String, String> map = new HashMap<String, String>();
String[] kvs = loadString.split(",");
for (String kv : kvs) {
String[] onekv = kv.split("=");
String key = onekv[0].trim();
String value = onekv[1].trim();
map.put(key, value);
}
method.invoke(newVdcConfig, map);
} else {
method.invoke(newVdcConfig, field.getAttribute("value"));
}
} catch (Exception e) {
System.err.println("Reflect fail,method= " + method + "e= " + e);
}
}
newVdcConfigList.add(newVdcConfig);
}
return newVdcConfigList;
}
use of com.emc.storageos.geomodel.VdcConfig in project coprhd-controller by CoprHD.
the class DBClient method dumpRecoverInfoToRecoverFile.
/**
* Dump the vdc config backup info for recovery
*
* @param RecoverFileName
*/
public void dumpRecoverInfoToRecoverFile(String RecoverFileName) {
List<VdcConfig> newVdcConfigList = readRecoverBackupInfo();
verifyVdcConfigs(newVdcConfigList);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try {
builder = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e) {
System.err.println("xml builder error: " + e);
}
Document doc = builder.newDocument();
Element root = doc.createElement("VdcConfigs");
doc.appendChild(root);
for (VdcConfig vdcConfig : newVdcConfigList) {
Element vdcConfigNode = doc.createElement("VdcConfig");
vdcConfigNode.setAttribute("id", vdcConfig.getId().toString());
root.appendChild(vdcConfigNode);
Method[] methods = vdcConfig.getClass().getDeclaredMethods();
for (Method method : methods) {
if (method.getName().contains("get") && !method.getName().contains("Id")) {
try {
Element fieldNode = doc.createElement("field");
Object name = method.getName().replace("get", "");
Object value = method.invoke(vdcConfig);
Object type = method.getReturnType().getName();
fieldNode.setAttribute("name", name.toString());
fieldNode.setAttribute("type", type.toString());
fieldNode.setAttribute("value", value == null ? "" : value.toString());
vdcConfigNode.appendChild(fieldNode);
} catch (Exception e) {
System.err.println("reflect fail: " + e);
}
}
}
}
try (FileOutputStream fos = new FileOutputStream(RecoverFileName);
StringWriter sw = new StringWriter()) {
Source source = new DOMSource(doc);
Result result = new StreamResult(sw);
Transformer xformer = TransformerFactory.newInstance().newTransformer();
xformer.setOutputProperty(OutputKeys.INDENT, "yes");
xformer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
xformer.transform(source, result);
byte[] encryptByte = geoEncryptionProvider.encrypt(sw.toString());
fos.write(encryptByte);
System.out.println(String.format("Dump into file: %s successfully", RecoverFileName));
log.info("Dump into file: {} successfully", RecoverFileName);
} catch (Exception e) {
System.err.println("fail to write to file : " + e);
}
}
use of com.emc.storageos.geomodel.VdcConfig in project coprhd-controller by CoprHD.
the class VdcConfigService method updateVdcStatusInDB.
private void updateVdcStatusInDB(List<VdcConfig> vdcConfigs) {
List<URI> vdcIdIter = new ArrayList<>();
List<URI> vdcIds = dbClient.queryByType(VirtualDataCenter.class, true);
for (URI id : vdcIds) {
vdcIdIter.add(id);
}
for (VdcConfig vdcConfig : vdcConfigs) {
log.info("current config's id is {}", vdcConfig.getId());
if (vdcIdIter.contains(vdcConfig.getId())) {
VirtualDataCenter vdc = dbClient.queryObject(VirtualDataCenter.class, vdcConfig.getId());
vdc.setConnectionStatus(VirtualDataCenter.ConnectionStatus.valueOf(vdcConfig.getConnectionStatus()));
dbClient.updateAndReindexObject(vdc);
}
}
}
use of com.emc.storageos.geomodel.VdcConfig in project coprhd-controller by CoprHD.
the class VdcConfigService method checkNodeConnections.
/**
* check to see if the individual nodes of one vdc are visible from another
*
* @param checkParam
* @return
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/nodecheck")
public VdcNodeCheckResponse checkNodeConnections(VdcNodeCheckParam checkParam, @HeaderParam("X-Forwarded-For") String clientIp) {
List<VdcConfig> vdcList = checkParam.getVirtualDataCenters();
log.info("checking nodes for vdcs {} ...", getVdcIds(vdcList));
if (service.getId().endsWith("standalone")) {
throw GeoException.fatals.remoteVDCWrongStandaloneInstall();
}
ArgValidator.checkFieldNotEmpty(vdcList, "vdc");
VirtualDataCenter localVdc = VdcUtil.getLocalVdc();
if (localVdc == null) {
throw GeoException.fatals.failedToFindLocalVDC();
}
return toVdcNodeCheckResponse(localVdc, helper.areNodesReachable(vdcList, false));
}
use of com.emc.storageos.geomodel.VdcConfig in project coprhd-controller by CoprHD.
the class VdcConfigHelper method toConfigParam.
/**
* Build VdcConfig for a vdc for SyncVdcConfig call
*
* @param vdcInfo
* @return
*/
public VdcConfig toConfigParam(Properties vdcInfo) {
log.info("copy {} to the sync config param", vdcInfo.getProperty(GeoServiceJob.VDC_SHORT_ID));
VdcConfig vdcConfig = new VdcConfig();
vdcConfig.setId(URIUtil.uri(vdcInfo.getProperty(GeoServiceJob.OPERATED_VDC_ID)));
vdcConfig.setShortId(vdcInfo.getProperty(GeoServiceJob.VDC_SHORT_ID));
vdcConfig.setSecretKey(vdcInfo.getProperty(GeoServiceJob.VDC_SECRETE_KEY));
String name = vdcInfo.getProperty(GeoServiceJob.VDC_NAME);
if ((name != null) && (!name.isEmpty())) {
vdcConfig.setName(name);
}
String description = vdcInfo.getProperty(GeoServiceJob.VDC_DESCRIPTION);
if ((description != null) && (!description.isEmpty())) {
vdcConfig.setDescription(description);
}
String endPnt = vdcInfo.getProperty(GeoServiceJob.VDC_API_ENDPOINT);
if (endPnt != null) {
vdcConfig.setApiEndpoint(endPnt);
}
vdcConfig.setGeoCommandEndpoint(vdcInfo.getProperty(GeoServiceJob.VDC_GEOCOMMAND_ENDPOINT));
vdcConfig.setGeoDataEndpoint(vdcInfo.getProperty(GeoServiceJob.VDC_GEODATA_ENDPOINT));
return vdcConfig;
}
Aggregations