Search in sources :

Example 16 with TblTaLog

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

the class TblTaLogJpaController method destroy.

public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblTaLog tblTaLog;
        try {
            tblTaLog = em.getReference(TblTaLog.class, id);
            tblTaLog.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The tblTaLog with id " + id + " no longer exists.", enfe);
        }
        em.remove(tblTaLog);
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) TblTaLog(com.intel.mtwilson.as.data.TblTaLog) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 17 with TblTaLog

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

the class TblTaLogJpaController method getTblTaLogCount.

public int getTblTaLogCount() {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        Root<TblTaLog> rt = cq.from(TblTaLog.class);
        cq.select(em.getCriteriaBuilder().count(rt));
        Query q = em.createQuery(cq);
        return ((Long) q.getSingleResult()).intValue();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) TblTaLog(com.intel.mtwilson.as.data.TblTaLog) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) CriteriaQuery(javax.persistence.criteria.CriteriaQuery)

Example 18 with TblTaLog

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

the class TblTaLogJpaController method getHostTALogEntryBefore.

public TblTaLog getHostTALogEntryBefore(int hostId, Date expiryTime) {
    EntityManager em = getEntityManager();
    try {
        Query query = em.createNamedQuery("TblTaLog.getHostTALogEntryBefore");
        query.setParameter("hostId", hostId);
        query.setParameter("expiryTs", expiryTime);
        List<TblTaLog> logs = query.getResultList();
        if (logs != null && logs.size() > 0) {
            return logs.get(0);
        }
    } finally {
        em.close();
    }
    return null;
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblTaLog(com.intel.mtwilson.as.data.TblTaLog)

Example 19 with TblTaLog

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

the class HostBO method deleteTALogs.

private void deleteTALogs(Integer hostId) throws IllegalOrphanException {
    TblTaLogJpaController tblTaLogJpaController = getTaLogJpaController();
    List<TblTaLog> taLogs = tblTaLogJpaController.findLogsByHostId(hostId, new Date());
    if (taLogs != null) {
        for (TblTaLog taLog : taLogs) {
            try {
                tblTaLogJpaController.destroy(taLog.getId());
            } catch (NonexistentEntityException e) {
                log.warn("Ta Log is already deleted " + taLog.getId());
            }
        }
        log.info("Deleted all the logs for the given host " + hostId);
    }
}
Also used : TblTaLogJpaController(com.intel.mtwilson.as.controller.TblTaLogJpaController) TblTaLog(com.intel.mtwilson.as.data.TblTaLog) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) Date(java.util.Date)

Example 20 with TblTaLog

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

the class HostTrustBO method logBlankTrustStatus.

/*Bug 510
     * Added to support removal of TPM from host which was previously enabled. 
     * Adding blank row to ta log table will prevent an invalid trust report
     */
private void logBlankTrustStatus(TblHosts host) {
    Date today = new Date(System.currentTimeMillis());
    TblTaLog taLog = new TblTaLog();
    taLog.setHostID(host.getId());
    taLog.setMleId(0);
    taLog.setTrustStatus(false);
    taLog.setManifestName("");
    taLog.setManifestValue("");
    taLog.setUpdatedOn(today);
    new TblTaLogJpaController(getEntityManagerFactory()).create(taLog);
}
Also used : TblTaLogJpaController(com.intel.mtwilson.as.controller.TblTaLogJpaController) TblTaLog(com.intel.mtwilson.as.data.TblTaLog) Date(java.util.Date)

Aggregations

TblTaLog (com.intel.mtwilson.as.data.TblTaLog)23 EntityManager (javax.persistence.EntityManager)11 Date (java.util.Date)9 Query (javax.persistence.Query)7 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)7 Hostname (com.intel.mtwilson.util.net.Hostname)6 TblHosts (com.intel.mtwilson.as.data.TblHosts)5 ASException (com.intel.mountwilson.as.common.ASException)4 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)4 CryptographyException (com.intel.mtwilson.crypto.CryptographyException)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 HostType (com.intel.mountwilson.as.hosttrustreport.data.HostType)3 TblTaLogJpaController (com.intel.mtwilson.as.controller.TblTaLogJpaController)3 EntityNotFoundException (javax.persistence.EntityNotFoundException)3 HostManifestReportType (com.intel.mountwilson.as.hostmanifestreport.data.HostManifestReportType)2 HostsTrustReportType (com.intel.mountwilson.as.hosttrustreport.data.HostsTrustReportType)2 TblModuleManifestLog (com.intel.mtwilson.as.data.TblModuleManifestLog)2 IOException (java.io.IOException)2 ManifestType (com.intel.mountwilson.as.hostmanifestreport.data.ManifestType)1