Search in sources :

Example 1 with VdcConfig

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;
}
Also used : HashMap(java.util.HashMap) BufferedInputStream(java.io.BufferedInputStream) ObjectInputStream(java.io.ObjectInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) Document(org.w3c.dom.Document) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) IOException(java.io.IOException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) VdcConfig(com.emc.storageos.geomodel.VdcConfig) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 2 with VdcConfig

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);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) Element(org.w3c.dom.Element) Method(java.lang.reflect.Method) Document(org.w3c.dom.Document) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) IOException(java.io.IOException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) TimeSeriesQueryResult(com.emc.storageos.db.client.TimeSeriesQueryResult) StreamResult(javax.xml.transform.stream.StreamResult) CheckResult(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult) Result(javax.xml.transform.Result) StringWriter(java.io.StringWriter) DocumentBuilder(javax.xml.parsers.DocumentBuilder) VdcConfig(com.emc.storageos.geomodel.VdcConfig) FileOutputStream(java.io.FileOutputStream) DataObject(com.emc.storageos.db.client.model.DataObject) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 3 with VdcConfig

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);
        }
    }
}
Also used : VdcConfig(com.emc.storageos.geomodel.VdcConfig) VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) URI(java.net.URI)

Example 4 with VdcConfig

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));
}
Also used : VdcConfig(com.emc.storageos.geomodel.VdcConfig) VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 5 with VdcConfig

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;
}
Also used : VdcConfig(com.emc.storageos.geomodel.VdcConfig)

Aggregations

VdcConfig (com.emc.storageos.geomodel.VdcConfig)18 VirtualDataCenter (com.emc.storageos.db.client.model.VirtualDataCenter)11 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)4 Site (com.emc.storageos.coordinator.client.model.Site)3 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)3 VdcConfigSyncParam (com.emc.storageos.geomodel.VdcConfigSyncParam)3 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)3 IntrospectionException (java.beans.IntrospectionException)3 IOException (java.io.IOException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 URI (java.net.URI)3 Date (java.util.Date)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 Method (java.lang.reflect.Method)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 NodeList (org.w3c.dom.NodeList)2 TimeSeriesQueryResult (com.emc.storageos.db.client.TimeSeriesQueryResult)1