Search in sources :

Example 16 with TblModuleManifest

use of com.intel.mtwilson.as.data.TblModuleManifest in project OpenAttestation by OpenAttestation.

the class HostBO method addModuleWhiteList.

private void addModuleWhiteList(PcrManifest pcr19, TblHosts tblHosts, TxtHost host, String uuid) {
    try {
        TblModuleManifestJpaController tblModuleManifestJpa = getModuleJpaController();
        TblMleJpaController tblMleJpa = getMleJpaController();
        TblEventTypeJpaController tblEventJpa = getEventJpaController();
        TblPackageNamespaceJpaController tblPackageJpa = getPackageJpaController();
        TblEventType tblEvent;
        TblMle tblMle = tblMleJpa.findTblMleByUUID(uuid);
        TblPackageNamespace nsPackNS;
        if (tblMle == null) {
            try {
                // First check if the entry exists in the MLE table.
                tblMle = getMleDetails(host.getVmm().getName(), host.getVmm().getVersion(), host.getVmm().getOsName(), host.getVmm().getOsVersion(), "");
            } catch (NoResultException nre) {
                throw new ASException(nre, ErrorCode.WS_MLE_DOES_NOT_EXIST, host.getVmm().getName(), host.getVmm().getVersion());
            }
        }
        if (tblMle == null) {
            log.error("MLE specified is not found in the DB");
            throw new ASException(ErrorCode.WS_MLE_RETRIEVAL_ERROR, this.getClass().getSimpleName());
        }
        String eventName;
        String componentName;
        //            String fullComponentName = "";
        String fullComponentName;
        String digest;
        String packageName;
        String packageVendor;
        String packageVersion;
        String extendedtoPCR;
        boolean useHostSpecificDigest;
        try {
            // Before we insert the record, we need the identity for the event name               
            if (pcr19.containsPcrEventLog(19)) {
                PcrEventLog pcrEventLog = pcr19.getPcrEventLog(19);
                if (pcrEventLog != null) {
                    for (Measurement m : pcrEventLog.getEventLog()) {
                        extendedtoPCR = m.getInfo().get("ExtendedToPCR");
                        if (extendedtoPCR != null) {
                            if (extendedtoPCR.equals("19")) {
                                //tblEvent = tblEventJpa.findEventTypeByName(m.getInfo().get("EventName"));
                                eventName = m.getInfo().get("EventName");
                                componentName = m.getInfo().get("ComponentName");
                                packageName = String.valueOf(m.getInfo().get("PackageName"));
                                packageVendor = String.valueOf(m.getInfo().get("PackageVendor"));
                                packageVersion = String.valueOf(m.getInfo().get("PackageVersion"));
                                extendedtoPCR = String.valueOf(m.getInfo().get("ExtendedToPCR"));
                                digest = String.valueOf(m.getValue());
                                useHostSpecificDigest = Boolean.valueOf(m.getInfo().get("UseHostSpecificDigest"));
                                try {
                                    // Before we insert the record, we need the identity for the event name
                                    tblEvent = tblEventJpa.findEventTypeByName(eventName);
                                } catch (NoResultException nre) {
                                    throw new ASException(nre, ErrorCode.WS_EVENT_TYPE_DOES_NOT_EXIST, eventName);
                                }
                                validateNull("EventName", eventName);
                                validateNull("ComponentName", componentName);
                                // corresponds to VMware, then we will append the event type fieldName to the component name. Otherwise we won't
                                if (eventName.contains("Vim25")) {
                                    fullComponentName = tblEvent.getFieldName() + "." + componentName;
                                } else {
                                    fullComponentName = componentName;
                                }
                                Integer componentID = tblModuleManifestJpa.findByMleIdEventId(tblMle.getId(), fullComponentName, tblEvent.getId());
                                if (componentID != null && componentID != 0) {
                                    throw new ASException(ErrorCode.WS_MODULE_WHITELIST_ALREADY_EXISTS, componentName);
                                }
                                try {
                                    // Since there will be only one entry for now, we will just hardcode it for now.
                                    // TO-DO: See if we can change this.
                                    // Nov-12,2013: Changed to use the function that accepts the ID instead of the name for better
                                    // performance.
                                    nsPackNS = tblPackageJpa.findByName("Standard_Global_NS");
                                } catch (NoResultException nre) {
                                    throw new ASException(ErrorCode.WS_NAME_SPACE_DOES_NOT_EXIST);
                                }
                                TblModuleManifest newModuleRecord = new TblModuleManifest();
                                if (uuid != null && !uuid.isEmpty()) {
                                    newModuleRecord.setUuid_hex(uuid);
                                } else {
                                    newModuleRecord.setUuid_hex(new UUID().toString());
                                }
                                newModuleRecord.setMleId(tblMle);
                                newModuleRecord.setMle_uuid_hex(tblMle.getUuid_hex());
                                newModuleRecord.setEventID(tblEvent);
                                newModuleRecord.setNameSpaceID(nsPackNS);
                                newModuleRecord.setComponentName(fullComponentName);
                                newModuleRecord.setDigestValue(digest);
                                newModuleRecord.setPackageName(packageName);
                                newModuleRecord.setPackageVendor(packageVendor);
                                newModuleRecord.setPackageVersion(packageVersion);
                                newModuleRecord.setUseHostSpecificDigestValue(useHostSpecificDigest);
                                newModuleRecord.setExtendedToPCR(extendedtoPCR);
                                newModuleRecord.setDescription("");
                                tblModuleManifestJpa.create(newModuleRecord);
                            //                                    break;
                            }
                        }
                    }
                }
            }
        } catch (NoResultException nre) {
            throw new ASException(nre, ErrorCode.WS_EVENT_TYPE_DOES_NOT_EXIST);
        }
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        //                    throw new ASException(ErrorCode.SYSTEM_ERROR, "Exception while adding Module white list data. " + e.getMessage(), e);
        // throw new ASException(e);
        log.error("Error during Module whitelist creation.", e);
        throw new ASException(ErrorCode.WS_MODULE_WHITELIST_CREATE_ERROR, e.getClass().getSimpleName());
    }
}
Also used : Measurement(com.intel.mtwilson.util.model.Measurement) TblMleJpaController(com.intel.mtwilson.as.controller.TblMleJpaController) TblPackageNamespaceJpaController(com.intel.mtwilson.as.controller.TblPackageNamespaceJpaController) TblMle(com.intel.mtwilson.as.data.TblMle) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) NoResultException(javax.persistence.NoResultException) PcrEventLog(com.intel.mtwilson.util.model.PcrEventLog) ASException(com.intel.mountwilson.as.common.ASException) NoResultException(javax.persistence.NoResultException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException) CryptographyException(com.intel.mtwilson.crypto.CryptographyException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) TblEventTypeJpaController(com.intel.mtwilson.as.controller.TblEventTypeJpaController) TblEventType(com.intel.mtwilson.as.data.TblEventType) TblModuleManifestJpaController(com.intel.mtwilson.as.controller.TblModuleManifestJpaController) UUID(com.intel.mtwilson.util.io.UUID) TblPackageNamespace(com.intel.mtwilson.as.data.TblPackageNamespace) ASException(com.intel.mountwilson.as.common.ASException)

Example 17 with TblModuleManifest

use of com.intel.mtwilson.as.data.TblModuleManifest in project OpenAttestation by OpenAttestation.

the class TblModuleManifestJpaController method findTblModuleManifestByComponentNameLike.

public List<TblModuleManifest> findTblModuleManifestByComponentNameLike(String moduleName) {
    EntityManager em = getEntityManager();
    try {
        Query query = em.createNamedQuery("TblModuleManifest.findByComponentNameLike");
        query.setParameter("name", "%" + moduleName + "%");
        List<TblModuleManifest> pcrList = query.getResultList();
        return pcrList;
    } catch (NoResultException e) {
        log.error(String.format("Module information with name {} not found in the DB.", moduleName));
        return null;
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) NoResultException(javax.persistence.NoResultException)

Example 18 with TblModuleManifest

use of com.intel.mtwilson.as.data.TblModuleManifest in project OpenAttestation by OpenAttestation.

the class TblModuleManifestJpaController method edit_v2.

public void edit_v2(TblModuleManifest tblModuleManifest, EntityManager em) throws IllegalOrphanException, NonexistentEntityException, ASDataException {
    try {
        TblModuleManifest persistentTblModuleManifest = em.find(TblModuleManifest.class, tblModuleManifest.getId());
        TblMle mleIdOld = persistentTblModuleManifest.getMleId();
        TblMle mleIdNew = tblModuleManifest.getMleId();
        TblEventType eventIDOld = persistentTblModuleManifest.getEventID();
        TblEventType eventIDNew = tblModuleManifest.getEventID();
        TblPackageNamespace nameSpaceIDOld = persistentTblModuleManifest.getNameSpaceID();
        TblPackageNamespace nameSpaceIDNew = tblModuleManifest.getNameSpaceID();
        Collection<TblHostSpecificManifest> tblHostSpecificManifestCollectionOld = persistentTblModuleManifest.getTblHostSpecificManifestCollection();
        Collection<TblHostSpecificManifest> tblHostSpecificManifestCollectionNew = tblModuleManifest.getTblHostSpecificManifestCollection();
        List<String> illegalOrphanMessages = null;
        for (TblHostSpecificManifest tblHostSpecificManifestCollectionOldTblHostSpecificManifest : tblHostSpecificManifestCollectionOld) {
            if (!tblHostSpecificManifestCollectionNew.contains(tblHostSpecificManifestCollectionOldTblHostSpecificManifest)) {
                if (illegalOrphanMessages == null) {
                    illegalOrphanMessages = new ArrayList<String>();
                }
                illegalOrphanMessages.add("You must retain TblHostSpecificManifest " + tblHostSpecificManifestCollectionOldTblHostSpecificManifest + " since its moduleManifestID field is not nullable.");
            }
        }
        if (illegalOrphanMessages != null) {
            throw new IllegalOrphanException(illegalOrphanMessages);
        }
        if (mleIdNew != null) {
            mleIdNew = em.getReference(mleIdNew.getClass(), mleIdNew.getId());
            tblModuleManifest.setMleId(mleIdNew);
        }
        if (eventIDNew != null) {
            eventIDNew = em.getReference(eventIDNew.getClass(), eventIDNew.getId());
            tblModuleManifest.setEventID(eventIDNew);
        }
        if (nameSpaceIDNew != null) {
            nameSpaceIDNew = em.getReference(nameSpaceIDNew.getClass(), nameSpaceIDNew.getId());
            tblModuleManifest.setNameSpaceID(nameSpaceIDNew);
        }
        Collection<TblHostSpecificManifest> attachedTblHostSpecificManifestCollectionNew = new ArrayList<TblHostSpecificManifest>();
        for (TblHostSpecificManifest tblHostSpecificManifestCollectionNewTblHostSpecificManifestToAttach : tblHostSpecificManifestCollectionNew) {
            tblHostSpecificManifestCollectionNewTblHostSpecificManifestToAttach = em.getReference(tblHostSpecificManifestCollectionNewTblHostSpecificManifestToAttach.getClass(), tblHostSpecificManifestCollectionNewTblHostSpecificManifestToAttach.getId());
            attachedTblHostSpecificManifestCollectionNew.add(tblHostSpecificManifestCollectionNewTblHostSpecificManifestToAttach);
        }
        tblHostSpecificManifestCollectionNew = attachedTblHostSpecificManifestCollectionNew;
        tblModuleManifest.setTblHostSpecificManifestCollection(tblHostSpecificManifestCollectionNew);
        tblModuleManifest = em.merge(tblModuleManifest);
        if (mleIdOld != null && !mleIdOld.equals(mleIdNew)) {
            mleIdOld.getTblModuleManifestCollection().remove(tblModuleManifest);
            mleIdOld = em.merge(mleIdOld);
        }
        if (mleIdNew != null && !mleIdNew.equals(mleIdOld)) {
            mleIdNew.getTblModuleManifestCollection().add(tblModuleManifest);
            em.merge(mleIdNew);
        }
        if (eventIDOld != null && !eventIDOld.equals(eventIDNew)) {
            eventIDOld.getTblModuleManifestCollection().remove(tblModuleManifest);
            eventIDOld = em.merge(eventIDOld);
        }
        if (eventIDNew != null && !eventIDNew.equals(eventIDOld)) {
            eventIDNew.getTblModuleManifestCollection().add(tblModuleManifest);
            em.merge(eventIDNew);
        }
        if (nameSpaceIDOld != null && !nameSpaceIDOld.equals(nameSpaceIDNew)) {
            nameSpaceIDOld.getTblModuleManifestCollection().remove(tblModuleManifest);
            nameSpaceIDOld = em.merge(nameSpaceIDOld);
        }
        if (nameSpaceIDNew != null && !nameSpaceIDNew.equals(nameSpaceIDOld)) {
            nameSpaceIDNew.getTblModuleManifestCollection().add(tblModuleManifest);
            em.merge(nameSpaceIDNew);
        }
        for (TblHostSpecificManifest tblHostSpecificManifestCollectionNewTblHostSpecificManifest : tblHostSpecificManifestCollectionNew) {
            if (!tblHostSpecificManifestCollectionOld.contains(tblHostSpecificManifestCollectionNewTblHostSpecificManifest)) {
                TblModuleManifest oldModuleManifestIDOfTblHostSpecificManifestCollectionNewTblHostSpecificManifest = tblHostSpecificManifestCollectionNewTblHostSpecificManifest.getModuleManifestID();
                tblHostSpecificManifestCollectionNewTblHostSpecificManifest.setModuleManifestID(tblModuleManifest);
                tblHostSpecificManifestCollectionNewTblHostSpecificManifest = em.merge(tblHostSpecificManifestCollectionNewTblHostSpecificManifest);
                if (oldModuleManifestIDOfTblHostSpecificManifestCollectionNewTblHostSpecificManifest != null && !oldModuleManifestIDOfTblHostSpecificManifestCollectionNewTblHostSpecificManifest.equals(tblModuleManifest)) {
                    oldModuleManifestIDOfTblHostSpecificManifestCollectionNewTblHostSpecificManifest.getTblHostSpecificManifestCollection().remove(tblHostSpecificManifestCollectionNewTblHostSpecificManifest);
                    em.merge(oldModuleManifestIDOfTblHostSpecificManifestCollectionNewTblHostSpecificManifest);
                }
            }
        }
    } catch (Exception ex) {
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            Integer id = tblModuleManifest.getId();
            if (findTblModuleManifest(id) == null) {
                throw new NonexistentEntityException("The tblModuleManifest with id " + id + " no longer exists.");
            }
        }
        throw new ASDataException(ex);
    } finally {
    }
}
Also used : IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) TblMle(com.intel.mtwilson.as.data.TblMle) ArrayList(java.util.ArrayList) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) NoResultException(javax.persistence.NoResultException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException) TblEventType(com.intel.mtwilson.as.data.TblEventType) TblHostSpecificManifest(com.intel.mtwilson.as.data.TblHostSpecificManifest) TblPackageNamespace(com.intel.mtwilson.as.data.TblPackageNamespace)

Example 19 with TblModuleManifest

use of com.intel.mtwilson.as.data.TblModuleManifest in project OpenAttestation by OpenAttestation.

the class TblModuleManifestJpaController method findTblModuleManifestEntities.

private List<TblModuleManifest> findTblModuleManifestEntities(boolean all, int maxResults, int firstResult) {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(TblModuleManifest.class));
        Query q = em.createQuery(cq);
        if (!all) {
            q.setMaxResults(maxResults);
            q.setFirstResult(firstResult);
        }
        return q.getResultList();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest)

Example 20 with TblModuleManifest

use of com.intel.mtwilson.as.data.TblModuleManifest in project OpenAttestation by OpenAttestation.

the class TblModuleManifestJpaController method create_v2.

public void create_v2(TblModuleManifest tblModuleManifest, EntityManager em) {
    long createV2_1 = System.currentTimeMillis();
    if (tblModuleManifest.getTblHostSpecificManifestCollection() == null) {
        tblModuleManifest.setTblHostSpecificManifestCollection(new ArrayList<TblHostSpecificManifest>());
    }
    try {
        TblMle mleId = tblModuleManifest.getMleId();
        if (mleId != null) {
            mleId = em.getReference(mleId.getClass(), mleId.getId());
            tblModuleManifest.setMleId(mleId);
        }
        TblEventType eventID = tblModuleManifest.getEventID();
        if (eventID != null) {
            eventID = em.getReference(eventID.getClass(), eventID.getId());
            tblModuleManifest.setEventID(eventID);
        }
        TblPackageNamespace nameSpaceID = tblModuleManifest.getNameSpaceID();
        if (nameSpaceID != null) {
            nameSpaceID = em.getReference(nameSpaceID.getClass(), nameSpaceID.getId());
            tblModuleManifest.setNameSpaceID(nameSpaceID);
        }
        long createV2_2 = System.currentTimeMillis();
        log.debug("CREATE_V2 - Time taken to setup IDs :" + (createV2_2 - createV2_1) + "milliseconds.");
        Collection<TblHostSpecificManifest> attachedTblHostSpecificManifestCollection = new ArrayList<TblHostSpecificManifest>();
        for (TblHostSpecificManifest tblHostSpecificManifestCollectionTblHostSpecificManifestToAttach : tblModuleManifest.getTblHostSpecificManifestCollection()) {
            tblHostSpecificManifestCollectionTblHostSpecificManifestToAttach = em.getReference(tblHostSpecificManifestCollectionTblHostSpecificManifestToAttach.getClass(), tblHostSpecificManifestCollectionTblHostSpecificManifestToAttach.getId());
            attachedTblHostSpecificManifestCollection.add(tblHostSpecificManifestCollectionTblHostSpecificManifestToAttach);
        }
        tblModuleManifest.setTblHostSpecificManifestCollection(attachedTblHostSpecificManifestCollection);
        em.persist(tblModuleManifest);
        long createV2_3 = System.currentTimeMillis();
        log.debug("CREATE_V2 - Time taken to insert and persist :" + (createV2_3 - createV2_2) + "milliseconds.");
        if (mleId != null) {
            mleId.getTblModuleManifestCollection().add(tblModuleManifest);
            em.merge(mleId);
        }
        if (eventID != null) {
            eventID.getTblModuleManifestCollection().add(tblModuleManifest);
            em.merge(eventID);
        }
        if (nameSpaceID != null) {
            nameSpaceID.getTblModuleManifestCollection().add(tblModuleManifest);
            em.merge(nameSpaceID);
        }
        for (TblHostSpecificManifest tblHostSpecificManifestCollectionTblHostSpecificManifest : tblModuleManifest.getTblHostSpecificManifestCollection()) {
            TblModuleManifest oldModuleManifestIDOfTblHostSpecificManifestCollectionTblHostSpecificManifest = tblHostSpecificManifestCollectionTblHostSpecificManifest.getModuleManifestID();
            tblHostSpecificManifestCollectionTblHostSpecificManifest.setModuleManifestID(tblModuleManifest);
            tblHostSpecificManifestCollectionTblHostSpecificManifest = em.merge(tblHostSpecificManifestCollectionTblHostSpecificManifest);
            if (oldModuleManifestIDOfTblHostSpecificManifestCollectionTblHostSpecificManifest != null) {
                oldModuleManifestIDOfTblHostSpecificManifestCollectionTblHostSpecificManifest.getTblHostSpecificManifestCollection().remove(tblHostSpecificManifestCollectionTblHostSpecificManifest);
                em.merge(oldModuleManifestIDOfTblHostSpecificManifestCollectionTblHostSpecificManifest);
            }
        }
        long createV2_4 = System.currentTimeMillis();
        log.debug("CREATE_V2 - Time taken for merge operations :" + (createV2_4 - createV2_3) + "milliseconds.");
    } finally {
    }
}
Also used : TblEventType(com.intel.mtwilson.as.data.TblEventType) TblMle(com.intel.mtwilson.as.data.TblMle) TblHostSpecificManifest(com.intel.mtwilson.as.data.TblHostSpecificManifest) ArrayList(java.util.ArrayList) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) TblPackageNamespace(com.intel.mtwilson.as.data.TblPackageNamespace)

Aggregations

TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)28 EntityManager (javax.persistence.EntityManager)21 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)11 NoResultException (javax.persistence.NoResultException)10 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)9 TblEventType (com.intel.mtwilson.as.data.TblEventType)9 TblHostSpecificManifest (com.intel.mtwilson.as.data.TblHostSpecificManifest)9 TblPackageNamespace (com.intel.mtwilson.as.data.TblPackageNamespace)9 ArrayList (java.util.ArrayList)9 EntityNotFoundException (javax.persistence.EntityNotFoundException)9 Query (javax.persistence.Query)9 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)9 TblMle (com.intel.mtwilson.as.data.TblMle)7 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)5 TblModuleManifestJpaController (com.intel.mtwilson.as.controller.TblModuleManifestJpaController)3 ASException (com.intel.mountwilson.as.common.ASException)2 TblHostSpecificManifestJpaController (com.intel.mtwilson.as.controller.TblHostSpecificManifestJpaController)2 TblMleJpaController (com.intel.mtwilson.as.controller.TblMleJpaController)2 Measurement (com.intel.mtwilson.util.model.Measurement)2 PcrEventLog (com.intel.mtwilson.util.model.PcrEventLog)2