Search in sources :

Example 6 with ScopedLabelSet

use of com.emc.storageos.db.client.model.ScopedLabelSet in project coprhd-controller by CoprHD.

the class ExportService method getListOfInitiators.

private List<Initiator> getListOfInitiators(Connector connector, String tenant_id, String protocol, Volume vol) {
    List<Initiator> initiators = new ArrayList<Initiator>();
    boolean bFound = false;
    if (protocol.equals(Protocol.iSCSI.name())) {
        // this is an iSCSI request
        String port = connector.initiator;
        String hostname = connector.host;
        List<Initiator> iscsi_initiators = new ArrayList<Initiator>();
        Boolean found = searchInDb(port, iscsi_initiators, Protocol.iSCSI.name());
        if (found) {
            initiators.addAll(iscsi_initiators);
        } else {
            // not found, create a new one
            _log.info("Creating new iSCSI initiator, iqn = {}", port);
            // Make sure the port is a valid iSCSI port.
            if (!iSCSIUtility.isValidIQNPortName(port) && !iSCSIUtility.isValidEUIPortName(port))
                throw APIException.badRequests.invalidIscsiInitiatorPort();
            // Find host, and if not found, create new host
            Host host = getHost(hostname, tenant_id);
            // create and populate the initiator
            Initiator initiator = new Initiator();
            initiator.setHost(host.getId());
            initiator.setHostName(connector.host);
            if (!NullColumnValueGetter.isNullURI(host.getCluster())) {
                Cluster cluster = queryObject(Cluster.class, host.getCluster(), false);
                initiator.setClusterName(cluster.getLabel());
            }
            initiator.setId(URIUtil.createId(Initiator.class));
            initiator.setInitiatorPort(port);
            // allows deletion via UI
            initiator.setIsManualCreation(true);
            initiator.setProtocol(HostInterface.Protocol.iSCSI.name());
            addInitiatorToNetwork(initiator, vol);
            ScopedLabelSet tags = new ScopedLabelSet();
            tags.add(new ScopedLabel("openstack", "dynamic"));
            initiator.setTag(tags);
            _dbClient.createObject(initiator);
            initiators.add(initiator);
        }
    } else if (protocol.equals(Protocol.FC.name())) {
        // this is an FC request
        for (String fc_port : connector.wwpns) {
            // See if this initiator exists in our DB
            List<Initiator> fc_initiators = new ArrayList<Initiator>();
            Boolean found = searchInDb(fc_port, fc_initiators, Protocol.FC.name());
            if (found) {
                bFound = true;
                initiators.addAll(fc_initiators);
            } else {
                // not found, we don't create dynamically for FC
                _log.info("FC initiator for wwpn {} not found", fc_port);
            }
        }
        if (!bFound) {
            throw APIException.internalServerErrors.genericApisvcError("Export Failed", new Exception("No FC initiator found for export"));
        }
    } else {
        throw APIException.internalServerErrors.genericApisvcError("Unsupported volume protocol", new Exception("The protocol specified is not supported. The protocols supported are " + Protocol.FC.name() + " and " + Protocol.iSCSI.name()));
    }
    return initiators;
}
Also used : ArrayList(java.util.ArrayList) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) Initiator(com.emc.storageos.db.client.model.Initiator) ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) List(java.util.List) ArrayList(java.util.ArrayList) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList)

Example 7 with ScopedLabelSet

use of com.emc.storageos.db.client.model.ScopedLabelSet in project coprhd-controller by CoprHD.

the class SnapshotService method createSnapshot.

/**
 * The snapshot of a volume in Block Store is a point in time copy of the
 * volume. This API allows the user to create snapshot of a volume
 * NOTE: This is an asynchronous operation.
 *
 * @prereq none
 *
 * @param param
 *            POST data containing the snapshot creation information.
 *
 * @brief Create snapshot
 * @return Details of the newly created snapshot
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response createSnapshot(@PathParam("tenant_id") String openstack_tenant_id, SnapshotCreateRequestGen param, @Context HttpHeaders header, @HeaderParam("X-Cinder-V1-Call") String isV1Call) throws InternalException {
    // Step 1: Parameter validation
    String snapshotName = null;
    String snapshotDescription = null;
    if (isV1Call != null) {
        snapshotName = param.snapshot.display_name;
        snapshotDescription = param.snapshot.display_description;
    } else {
        snapshotName = param.snapshot.name;
        snapshotDescription = param.snapshot.description;
    }
    // if snapshot name is empty create random name
    if (snapshotName == null) {
        snapshotName = "snapshot-" + RandomStringUtils.random(10);
    }
    if (snapshotName == null || (snapshotName.length() <= 2)) {
        throw APIException.badRequests.parameterIsNotValid(param.snapshot.name);
    }
    URI volumeUri = null;
    Volume volume = null;
    volumeUri = URI.create(param.snapshot.volume_id);
    volume = queryVolumeResource(volumeUri, openstack_tenant_id);
    if (volume == null) {
        _log.error("Invalid source volume id to create snapshot ={} ", param.snapshot.volume_id);
        return CinderApiUtils.createErrorResponse(404, "Not Found : Invalid source volume id " + param.snapshot.volume_id);
    }
    VirtualPool pool = _dbClient.queryObject(VirtualPool.class, volume.getVirtualPool());
    if (pool == null) {
        _log.info("Virtual Pool corresponding to the volume does not exist.");
        throw APIException.badRequests.parameterIsNotValid(volume.getVirtualPool().toString());
    }
    if (!validateSnapshotCreate(openstack_tenant_id, pool, volume.getProvisionedCapacity())) {
        _log.info("The volume can not be created because of insufficient quota for virtual pool.");
        throw APIException.badRequests.insufficientQuotaForVirtualPool(pool.getLabel(), "virtual pool");
    }
    if (!validateSnapshotCreate(openstack_tenant_id, null, volume.getProvisionedCapacity())) {
        _log.info("The volume can not be created because of insufficient quota for Project.");
        throw APIException.badRequests.insufficientQuotaForProject(pool.getLabel(), "project");
    }
    BlockFullCopyManager fcManager = new BlockFullCopyManager(_dbClient, _permissionsHelper, _auditMgr, _coordinator, _placementManager, sc, uriInfo, _request, _tenantsService);
    VolumeIngestionUtil.checkOperationSupportedOnIngestedVolume(volume, ResourceOperationTypeEnum.CREATE_VOLUME_SNAPSHOT, _dbClient);
    // Don't operate on VPLEX backend volumes or RP journal volumes.
    BlockServiceUtils.validateNotAnInternalBlockObject(volume, false);
    validateSourceVolumeHasExported(volume);
    String snapshotType = TechnologyType.NATIVE.toString();
    Boolean createInactive = Boolean.FALSE;
    Boolean readOnly = Boolean.FALSE;
    BlockServiceApi api = getBlockServiceImpl(pool, _dbClient);
    List<Volume> volumesToSnap = new ArrayList<Volume>();
    volumesToSnap.addAll(api.getVolumesToSnap(volume, snapshotType));
    api.validateCreateSnapshot(volume, volumesToSnap, snapshotType, snapshotName, readOnly, fcManager);
    String taskId = UUID.randomUUID().toString();
    List<URI> snapshotURIs = new ArrayList<URI>();
    List<BlockSnapshot> snapshots = api.prepareSnapshots(volumesToSnap, snapshotType, snapshotName, snapshotURIs, taskId);
    TaskList response = new TaskList();
    for (BlockSnapshot snapshot : snapshots) {
        response.getTaskList().add(toTask(snapshot, taskId));
    }
    // Update the task status for the volumes task.
    _dbClient.createTaskOpStatus(Volume.class, volume.getId(), taskId, ResourceOperationTypeEnum.CREATE_VOLUME_SNAPSHOT);
    // Invoke the block service API implementation to create the snapshot
    api.createSnapshot(volume, snapshotURIs, snapshotType, createInactive, readOnly, taskId);
    SnapshotCreateResponse snapCreateResp = new SnapshotCreateResponse();
    for (TaskResourceRep rep : response.getTaskList()) {
        URI snapshotUri = rep.getResource().getId();
        BlockSnapshot snap = _dbClient.queryObject(BlockSnapshot.class, snapshotUri);
        if (snap != null) {
            StringMap extensions = snap.getExtensions();
            if (extensions == null)
                extensions = new StringMap();
            extensions.put("display_description", (snapshotDescription == null) ? "" : snapshotDescription);
            extensions.put("taskid", rep.getId().toString());
            _log.debug("Create snapshot : stored description");
            snap.setExtensions(extensions);
            ScopedLabelSet tagSet = new ScopedLabelSet();
            snap.setTag(tagSet);
            String[] splits = snapshotUri.toString().split(":");
            String tagName = splits[3];
            // this check will verify whether  retrieved data is not corrupted
            if (tagName == null || tagName.isEmpty() || tagName.length() < 2) {
                throw APIException.badRequests.parameterTooShortOrEmpty("Tag", 2);
            }
            Volume parentVol = _permissionsHelper.getObjectById(snap.getParent(), Volume.class);
            URI tenantOwner = parentVol.getTenant().getURI();
            ScopedLabel tagLabel = new ScopedLabel(tenantOwner.toString(), tagName);
            tagSet.add(tagLabel);
            _dbClient.updateObject(snap);
            if (isV1Call != null) {
                _log.debug("Inside V1 call");
                return CinderApiUtils.getCinderResponse(getSnapshotDetail(snap, isV1Call, openstack_tenant_id), header, true, CinderConstants.STATUS_OK);
            } else {
                return CinderApiUtils.getCinderResponse(getSnapshotDetail(snap, isV1Call, openstack_tenant_id), header, true, CinderConstants.STATUS_ACCEPT);
            }
        }
    }
    return CinderApiUtils.getCinderResponse(new CinderSnapshot(), header, true, CinderConstants.STATUS_ACCEPT);
}
Also used : SnapshotCreateResponse(com.emc.storageos.cinder.model.SnapshotCreateResponse) StringMap(com.emc.storageos.db.client.model.StringMap) TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) BlockServiceApi(com.emc.storageos.api.service.impl.resource.BlockServiceApi) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) BlockFullCopyManager(com.emc.storageos.api.service.impl.resource.fullcopy.BlockFullCopyManager) CinderSnapshot(com.emc.storageos.cinder.model.CinderSnapshot) Volume(com.emc.storageos.db.client.model.Volume) ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 8 with ScopedLabelSet

use of com.emc.storageos.db.client.model.ScopedLabelSet in project coprhd-controller by CoprHD.

the class XIVSmisCommandHelper method unsetTag.

public void unsetTag(DataObject object, String scope) {
    ScopedLabelSet tagSet = object.getTag();
    if (tagSet == null) {
        return;
    }
    removeLabel(tagSet, scope);
    _dbClient.persistObject(object);
}
Also used : ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet)

Example 9 with ScopedLabelSet

use of com.emc.storageos.db.client.model.ScopedLabelSet in project coprhd-controller by CoprHD.

the class DbClientTest method testTagIndex.

@Test
public void testTagIndex() throws Exception {
    _logger.info("Starting testTagIndex");
    final int objCount = 1000;
    final String prefix = "55";
    Set<URI> expectedResult = new HashSet<URI>();
    URI tenant = URIUtil.createId(TenantOrg.class);
    DbClient dbClient = _dbClient;
    for (int index = 0; index < objCount; index++) {
        FileShare fs = new FileShare();
        fs.setId(URIUtil.createId(FileShare.class));
        fs.setLabel("foobar");
        String tag = String.format("%1$d - test label", index);
        if (tag.startsWith(prefix)) {
            expectedResult.add(fs.getId());
        }
        ScopedLabelSet tagSet = new ScopedLabelSet();
        tagSet.add(new ScopedLabel(tenant.toString(), tag));
        fs.setTag(tagSet);
        dbClient.persistObject(fs);
    }
    List<URI> hits = dbClient.queryByConstraint(PrefixConstraint.Factory.getTagsPrefixConstraint(FileShare.class, prefix, null));
    Assert.assertEquals(hits.size(), expectedResult.size());
    for (int i = 0; i < hits.size(); i++) {
        Assert.assertTrue(expectedResult.contains(hits.get(i)));
    }
    hits = dbClient.queryByConstraint(PrefixConstraint.Factory.getTagsPrefixConstraint(FileShare.class, prefix, tenant));
    Assert.assertEquals(hits.size(), expectedResult.size());
    for (int i = 0; i < hits.size(); i++) {
        Assert.assertTrue(expectedResult.contains(hits.get(i)));
    }
    hits = dbClient.queryByConstraint(PrefixConstraint.Factory.getTagsPrefixConstraint(FileShare.class, "foobar", tenant));
    Assert.assertEquals(hits.size(), 0);
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) InternalDbClient(com.emc.storageos.db.client.upgrade.InternalDbClient) ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) FileShare(com.emc.storageos.db.client.model.FileShare) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) AggregatedConstraint(com.emc.storageos.db.client.constraint.AggregatedConstraint) ContainmentPermissionsConstraint(com.emc.storageos.db.client.constraint.ContainmentPermissionsConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with ScopedLabelSet

use of com.emc.storageos.db.client.model.ScopedLabelSet in project coprhd-controller by CoprHD.

the class DbCli method readXMLAndPersist.

/**
 * Load xml file and save model object into Cassandra.
 *
 * @Param fileName
 */
private <T extends DataObject> void readXMLAndPersist(String fileName, DbCliOperation operation) throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = dbf.newDocumentBuilder();
    Document doc = builder.parse(fileName);
    // Read root node
    Element root = doc.getDocumentElement();
    Element dataObjectNode = (Element) root.getElementsByTagName("data_object_schema").item(0);
    // Get column family's name
    String cfName = dataObjectNode.getAttribute("name");
    System.out.println("Column Family based on XML: " + cfName);
    NodeList recordNodes = dataObjectNode.getElementsByTagName("record");
    Class<T> clazz = _cfMap.get(cfName);
    if (clazz == null) {
        System.out.println("Unknown Column Family: " + cfName);
        return;
    }
    // Get class info
    BeanInfo bInfo;
    try {
        bInfo = Introspector.getBeanInfo(clazz);
    } catch (IntrospectionException ex) {
        throw new RuntimeException("Unexpected exception getting bean info", ex);
    }
    PropertyDescriptor[] pds = bInfo.getPropertyDescriptors();
    // get position of xml node
    InputStream xmlIs = new FileInputStream(new File(fileName));
    Document docForPosition = PositionalXMLReader.readXML(xmlIs);
    xmlIs.close();
    for (int i = 0; i < recordNodes.getLength(); i++) {
        Element record = (Element) recordNodes.item(i);
        T object = null;
        String idStr = null;
        if (operation == DbCliOperation.LOAD) {
            // query record based id
            String recordId = record.getAttribute("id");
            System.out.println(String.format("Object id:\t%s", recordId));
            idStr = recordId;
            object = queryObject(URI.create(recordId), clazz);
        } else if (operation == DbCliOperation.CREATE) {
            // create new id for create record
            URI id = URIUtil.createId(clazz);
            object = clazz.newInstance();
            object.setId(id);
            System.out.println(String.format("Create new data object id:\t%s", object.getId()));
            idStr = object.getId().toString();
        }
        HashMap<String, String> fieldValueMap = new HashMap<String, String>();
        HashMap<String, Class> fieldTypeMap = new HashMap<String, Class>();
        HashMap<String, String> fieldLocationMap = new HashMap<String, String>();
        HashMap<String, Node> fieldNodeMap = new HashMap<String, Node>();
        NodeList fields = record.getElementsByTagName("field");
        // get field info from xml file
        for (int j = 0; j < fields.getLength(); j++) {
            Element field = (Element) fields.item(j);
            if (DEBUG) {
                System.out.println(field.getAttribute("name") + "\t" + field.getAttribute("type") + "\t" + field.getAttribute("value"));
            }
            fieldValueMap.put(field.getAttribute("name"), field.getAttribute("value"));
            fieldTypeMap.put(field.getAttribute("name"), Class.forName(field.getAttribute("type")));
            fieldLocationMap.put(field.getAttribute("name"), ((Element) docForPosition.getElementsByTagName("record").item(i)).getElementsByTagName("field").item(j).getUserData("lineNumber").toString());
            if (field.getElementsByTagName("wrapper").item(0) != null) {
                fieldNodeMap.put(field.getAttribute("name"), field.getElementsByTagName("wrapper").item(0));
            }
        }
        Iterator locationIt = fieldLocationMap.entrySet().iterator();
        while (locationIt.hasNext()) {
            Entry entry = (Entry) locationIt.next();
            String key = (String) entry.getKey();
            String value = (String) entry.getValue();
            if (DEBUG) {
                System.out.println("key:\t" + key + "\tvalue\t" + value);
            }
        }
        // update object's fields
        for (PropertyDescriptor pd : pds) {
            // skip class property, id property
            if (pd.getName().equals("class") || pd.getName().equals("id")) {
                continue;
            }
            Name name = pd.getReadMethod().getAnnotation(Name.class);
            if (name == null) {
                log.info("Ignore data object fields without @Name annotation, fieldName={}.", pd.getName());
                continue;
            }
            String objKey = name.value();
            String fieldValue = fieldValueMap.get(objKey);
            if (fieldValue == null) {
                // To support xml file that the old version dumped, it used method name not @Name value
                objKey = pd.getName();
            }
            fieldValue = fieldValueMap.get(objKey);
            Class fieldClass = fieldTypeMap.get(objKey);
            String fieldLocation = fieldLocationMap.get(objKey);
            Node fieldNode = fieldNodeMap.get(objKey);
            if (fieldValue != null) {
                Class type = pd.getPropertyType();
                if (DEBUG) {
                    System.out.print("\t" + objKey + " = " + type);
                }
                try {
                    if (type == URI.class) {
                        pd.getWriteMethod().invoke(object, URI.create(fieldValue));
                    } else if (type == NamedURI.class) {
                        pd.getWriteMethod().invoke(object, NamedURI.fromString(fieldValue));
                    } else if (type == Date.class) {
                    // Can not find records with value which owns this type. Remains to be verified correct or not.
                    // System.out.println("\ttype: Date ");
                    } else if (type == Calendar.class) {
                        Calendar calendar = FieldType.toCalendar(fieldValue);
                        if (!verifyField(calendar)) {
                            throw new Exception("field format exception");
                        }
                        pd.getWriteMethod().invoke(object, calendar);
                    } else if (type == StringMap.class) {
                        StringMap newStringMap = FieldType.convertType(fieldNode, StringMapWrapper.class);
                        if (!verifyField(newStringMap)) {
                            throw new Exception("field format exception");
                        }
                        StringMap sMap = (StringMap) pd.getReadMethod().invoke(object);
                        if (sMap == null) {
                            sMap = new StringMap();
                        }
                        sMap.clear();
                        Set<String> keys = newStringMap.keySet();
                        for (String key : keys) {
                            sMap.put(key, newStringMap.get(key));
                        }
                        pd.getWriteMethod().invoke(object, sMap);
                    } else if (type == StringSet.class) {
                        StringSet stringSet = FieldType.convertType(fieldNode, StringSetWrapper.class);
                        if (!verifyField(stringSet)) {
                            throw new Exception("field format exception");
                        }
                        StringSet updateSet = (StringSet) pd.getReadMethod().invoke(object);
                        if (updateSet != null) {
                            updateSet.clear();
                            updateSet.addAll(stringSet);
                        } else {
                            pd.getWriteMethod().invoke(object, stringSet);
                        }
                    } else if (type == OpStatusMap.class) {
                        OpStatusMap opStatusMap = FieldType.convertType(fieldNode, OpStatusMapWrapper.class);
                        if (!verifyField(opStatusMap)) {
                            throw new Exception("field format exception");
                        }
                    } else if (type == StringSetMap.class) {
                        StringSetMap newSetMap = FieldType.convertType(fieldNode, StringSetMapWrapper.class);
                        if (!verifyField(newSetMap)) {
                            throw new Exception("field format exception");
                        }
                        StringSetMap sMap = (StringSetMap) pd.getReadMethod().invoke(object);
                        if (sMap == null) {
                            sMap = new StringSetMap();
                        }
                        Set<String> keys = sMap.keySet();
                        for (String key : keys) {
                            sMap.remove(key);
                        }
                        keys = newSetMap.keySet();
                        for (String key : keys) {
                            sMap.put(key, newSetMap.get(key));
                        }
                    } else if (type == FSExportMap.class) {
                        FSExportMap fSExportMap = FieldType.convertType(fieldNode, FSExportMapWrapper.class);
                        if (!verifyField(fSExportMap)) {
                            throw new Exception("field format exception");
                        }
                        pd.getWriteMethod().invoke(object, fSExportMap);
                    } else if (type == SMBShareMap.class) {
                        SMBShareMap sMBShareMap = FieldType.convertType(fieldNode, SMBShareMapWrapper.class);
                        if (!verifyField(sMBShareMap)) {
                            throw new Exception("field format exception");
                        }
                        pd.getWriteMethod().invoke(object, sMBShareMap);
                    } else if (type == ScopedLabelSet.class) {
                        ScopedLabelSet scopedLabelSet = FieldType.convertType(fieldNode, ScopedLabelSetWrapper.class);
                        if (!verifyField(scopedLabelSet)) {
                            throw new Exception("field format exception");
                        }
                        ScopedLabelSet updateSet = (ScopedLabelSet) pd.getReadMethod().invoke(object);
                        if (updateSet != null) {
                            updateSet.clear();
                            updateSet.addAll(scopedLabelSet);
                        } else {
                            pd.getWriteMethod().invoke(object, scopedLabelSet);
                        }
                    } else if (type == String.class) {
                        pd.getWriteMethod().invoke(object, fieldClass.cast(fieldValue));
                    } else if (type.isEnum()) {
                        Object enumTypeObject = null;
                        try {
                            enumTypeObject = Enum.valueOf(type, fieldValue);
                        } catch (Exception e) {
                            throw new Exception("field format exception");
                        }
                        pd.getWriteMethod().invoke(object, enumTypeObject);
                    } else if (type == Integer.class) {
                        Integer intNum = FieldType.toInteger(fieldValue);
                        if (!verifyField(intNum)) {
                            throw new Exception("field format exception");
                        }
                        pd.getWriteMethod().invoke(object, intNum);
                    } else if (type == Boolean.class) {
                        Boolean boolVal = FieldType.toBoolean(fieldValue);
                        if (!verifyField(boolVal)) {
                            throw new Exception("field format exception");
                        }
                        pd.getWriteMethod().invoke(object, boolVal);
                    } else if (type == Long.class) {
                        Long longNum = FieldType.toLong(fieldValue);
                        if (!verifyField(longNum)) {
                            throw new Exception("field format exception");
                        }
                        pd.getWriteMethod().invoke(object, longNum);
                    } else if (type == Short.class) {
                        Short shortNum = FieldType.toShort(fieldValue);
                        if (!verifyField(shortNum)) {
                            throw new Exception("field format exception");
                        }
                        pd.getWriteMethod().invoke(object, shortNum);
                    } else if (type == Double.class) {
                        Double doubleNum = FieldType.toDouble(fieldValue);
                        if (!verifyField(doubleNum)) {
                            throw new Exception("field format exception");
                        }
                        pd.getWriteMethod().invoke(object, doubleNum);
                    } else {
                        pd.getWriteMethod().invoke(object, fieldValue);
                    }
                } catch (Exception e) {
                    System.out.println(String.format("Exception in getting field:%s in xml file line:%s.", pd.getName(), fieldLocation));
                    log.error("Exception in getting field value in xml file line:{}.", fieldLocation, e);
                    throw new Exception(String.format("Exception in getting field value in line:%s.", fieldLocation));
                }
                if (DEBUG) {
                    Object fieldValue1 = pd.getReadMethod().invoke(object);
                    System.out.println("write " + fieldValue1 + "\ttype: " + type + " success");
                }
            }
        }
        if (operation == DbCliOperation.CREATE) {
            // Save model object.
            _dbClient.createObject(object);
        } else if (operation == DbCliOperation.LOAD) {
            _dbClient.persistObject(object);
        }
        log.info(String.format("Successfully update Column family:%s, \tdata object id:%s \tinto Cassandra, based on xml file %s", cfName, idStr, fileName));
    }
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Set(java.util.Set) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) StringSet(com.emc.storageos.db.client.model.StringSet) HashMap(java.util.HashMap) NamedURI(com.emc.storageos.db.client.model.NamedURI) Element(org.w3c.dom.Element) BeanInfo(java.beans.BeanInfo) Node(org.w3c.dom.Node) IntrospectionException(java.beans.IntrospectionException) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) StringSetMapWrapper(com.emc.storageos.dbcli.wrapper.StringSetMapWrapper) Document(org.w3c.dom.Document) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Name(com.emc.storageos.db.client.model.Name) Entry(java.util.Map.Entry) Iterator(java.util.Iterator) StringSet(com.emc.storageos.db.client.model.StringSet) StringSetWrapper(com.emc.storageos.dbcli.wrapper.StringSetWrapper) SMBShareMapWrapper(com.emc.storageos.dbcli.wrapper.SMBShareMapWrapper) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) PropertyDescriptor(java.beans.PropertyDescriptor) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) NodeList(org.w3c.dom.NodeList) Calendar(java.util.Calendar) FileInputStream(java.io.FileInputStream) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) IntrospectionException(java.beans.IntrospectionException) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) DocumentBuilder(javax.xml.parsers.DocumentBuilder) DataObject(com.emc.storageos.db.client.model.DataObject) File(java.io.File)

Aggregations

ScopedLabelSet (com.emc.storageos.db.client.model.ScopedLabelSet)19 ScopedLabel (com.emc.storageos.db.client.model.ScopedLabel)14 URI (java.net.URI)8 StringMap (com.emc.storageos.db.client.model.StringMap)6 Volume (com.emc.storageos.db.client.model.Volume)6 NamedURI (com.emc.storageos.db.client.model.NamedURI)5 Project (com.emc.storageos.db.client.model.Project)4 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)4 Produces (javax.ws.rs.Produces)4 BlockServiceApi (com.emc.storageos.api.service.impl.resource.BlockServiceApi)3 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)3 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)3 DataObject (com.emc.storageos.db.client.model.DataObject)3 Host (com.emc.storageos.db.client.model.Host)3 StringSet (com.emc.storageos.db.client.model.StringSet)3 TaskList (com.emc.storageos.model.TaskList)3 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)3 ArrayList (java.util.ArrayList)3 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3