Search in sources :

Example 31 with TblHosts

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

the class HostBOTest method mockGetHost.

public TblHosts mockGetHost() {
    TblHosts tblHosts = new TblHosts();
    tblHosts.setId(1);
    tblHosts.setName(SERVER_NAME);
    tblHosts.setIPAddress(SERVER_NAME);
    String biosName = "DELL";
    String biosVersion = "A08";
    String oemName = "DELL";
    TblMle biosMle = new TblMle();
    biosMle.setId(1);
    biosMle.setName(biosName);
    biosMle.setVersion(biosVersion);
    TblOem oem = new TblOem();
    oem.setId(1);
    oem.setName(oemName);
    biosMle.setOemId(oem);
    Collection<TblPcrManifest> tblPcrManifestCollection = new ArrayList<TblPcrManifest>();
    TblPcrManifest tblPcrManifest = new TblPcrManifest();
    tblPcrManifest.setId(1);
    tblPcrManifest.setName("0");
    tblPcrManifest.setValue("31B97D97B4679917EC3C1D943635693FFBAB4143");
    tblPcrManifestCollection.add(tblPcrManifest);
    biosMle.setTblPcrManifestCollection(tblPcrManifestCollection);
    tblHosts.setBiosMleId(biosMle);
    String vmmName = "XEN";
    String vmmVersion = "4.3";
    String osName = "Fedora";
    String osVersion = "20";
    TblMle vmmMle = new TblMle();
    vmmMle.setId(1);
    vmmMle.setName(vmmName);
    vmmMle.setVersion(vmmVersion);
    TblOs os = new TblOs();
    os.setId(1);
    os.setName(osName);
    os.setVersion(osVersion);
    vmmMle.setOsId(os);
    Collection<TblPcrManifest> tblPcrManifestCollectionVMM = new ArrayList<TblPcrManifest>();
    TblPcrManifest tblPcrManifestVMM = new TblPcrManifest();
    tblPcrManifestVMM.setId(2);
    tblPcrManifestVMM.setName("18");
    tblPcrManifestVMM.setValue("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
    tblPcrManifestCollection.add(tblPcrManifestVMM);
    vmmMle.setTblPcrManifestCollection(tblPcrManifestCollectionVMM);
    tblHosts.setVmmMleId(vmmMle);
    tblHosts.setTlsPolicyName("");
    tblHosts.setPort(8181);
    return tblHosts;
}
Also used : TblHosts(com.intel.mtwilson.as.data.TblHosts) TblMle(com.intel.mtwilson.as.data.TblMle) TblOem(com.intel.mtwilson.as.data.TblOem) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest) TblOs(com.intel.mtwilson.as.data.TblOs)

Example 32 with TblHosts

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

the class ReportsBOTest method mockFindByName.

public TblHosts mockFindByName() {
    TblHosts tblHosts = new TblHosts();
    tblHosts.setId(1);
    tblHosts.setName(SERVER_NAME);
    tblHosts.setIPAddress(SERVER_NAME);
    String biosName = "DELL";
    String biosVersion = "A08";
    String oemName = "DELL";
    TblMle biosMle = new TblMle();
    biosMle.setId(1);
    biosMle.setName(biosName);
    biosMle.setVersion(biosVersion);
    TblOem oem = new TblOem();
    oem.setId(1);
    oem.setName(oemName);
    biosMle.setOemId(oem);
    Collection<TblPcrManifest> tblPcrManifestCollection = new ArrayList<TblPcrManifest>();
    TblPcrManifest tblPcrManifest = new TblPcrManifest();
    tblPcrManifest.setId(1);
    tblPcrManifest.setName("0");
    tblPcrManifest.setValue("31B97D97B4679917EC3C1D943635693FFBAB4143");
    tblPcrManifestCollection.add(tblPcrManifest);
    biosMle.setTblPcrManifestCollection(tblPcrManifestCollection);
    tblHosts.setBiosMleId(biosMle);
    String vmmName = "XEN";
    String vmmVersion = "4.3";
    String osName = "Fedora";
    String osVersion = "20";
    TblMle vmmMle = new TblMle();
    vmmMle.setId(1);
    vmmMle.setName(vmmName);
    vmmMle.setVersion(vmmVersion);
    TblOs os = new TblOs();
    os.setId(1);
    os.setName(osName);
    os.setVersion(osVersion);
    vmmMle.setOsId(os);
    Collection<TblPcrManifest> tblPcrManifestCollectionVMM = new ArrayList<TblPcrManifest>();
    TblPcrManifest tblPcrManifestVMM = new TblPcrManifest();
    tblPcrManifestVMM.setId(2);
    tblPcrManifestVMM.setName("18");
    tblPcrManifestVMM.setValue("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
    tblPcrManifestCollectionVMM.add(tblPcrManifestVMM);
    vmmMle.setTblPcrManifestCollection(tblPcrManifestCollectionVMM);
    tblHosts.setVmmMleId(vmmMle);
    return tblHosts;
}
Also used : TblHosts(com.intel.mtwilson.as.data.TblHosts) TblMle(com.intel.mtwilson.as.data.TblMle) TblOem(com.intel.mtwilson.as.data.TblOem) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest) TblOs(com.intel.mtwilson.as.data.TblOs)

Example 33 with TblHosts

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

the class HostBO method queryForHosts.

/**
         * Author: Sudhir
         *
         * Searches for the hosts using the criteria specified.
         *
         * @param searchCriteria: If in case the user has not provided any
         * search criteria, then all the hosts would be returned back to the
         * caller
         * @param includeHardwareUuid: if this is set to true, it causes the resulting 
         * TxtHostRecord to include the hardware_uuid field from the tblHost
         * @return
         */
public List<TxtHostRecord> queryForHosts(String searchCriteria, boolean includeHardwareUuid) {
    log.debug("queryForHost " + searchCriteria + " includeHardwareUuid[" + includeHardwareUuid + "]");
    try {
        //TblHostsJpaController tblHostsJpaController = My.jpa().mwHosts(); //new TblHostsJpaController(getEntityManagerFactory());
        TblHostsJpaController tblHostsJpaController = new TblHostsJpaController(getEntityManagerFactory());
        List<TxtHostRecord> txtHostList = new ArrayList<TxtHostRecord>();
        List<TblHosts> tblHostList;
        if (searchCriteria != null && !searchCriteria.isEmpty()) {
            tblHostList = tblHostsJpaController.findHostsByNameSearchCriteria(searchCriteria);
        } else {
            tblHostList = tblHostsJpaController.findTblHostsEntities();
        }
        if (tblHostList != null) {
            log.debug(String.format("Found [%d] host results for search criteria [%s]", tblHostList.size(), searchCriteria));
            for (TblHosts tblHosts : tblHostList) {
                TxtHostRecord hostObj = createTxtHostFromDatabaseRecord(tblHosts, includeHardwareUuid);
                txtHostList.add(hostObj);
            }
        } else {
            log.debug(String.format("Found no hosts for search criteria [%s]", searchCriteria));
        }
        return txtHostList;
    } catch (ASException e) {
        throw e;
    } catch (Exception e) {
        // throw new ASException(e);
        // Bug: 1038 - prevent leaks in error messages to client
        log.error("Error during querying for registered hosts.", e);
        throw new ASException(ErrorCode.AS_QUERY_HOST_ERROR, e.getClass().getSimpleName());
    }
}
Also used : TblHostsJpaController(com.intel.mtwilson.as.controller.TblHostsJpaController) TblHosts(com.intel.mtwilson.as.data.TblHosts) ArrayList(java.util.ArrayList) ASException(com.intel.mountwilson.as.common.ASException) 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)

Example 34 with TblHosts

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

the class HostBO method isHostRegistered.

public HostResponse isHostRegistered(String hostnameOrAddress) {
    try {
        TblHostsJpaController tblHostsJpaController = new TblHostsJpaController(getEntityManagerFactory());
        TblHosts tblHosts = tblHostsJpaController.findByName(hostnameOrAddress);
        if (tblHosts != null) {
            // host name exists in database
            return new HostResponse(ErrorCode.OK);
        }
        tblHosts = tblHostsJpaController.findByIPAddress(hostnameOrAddress);
        if (tblHosts != null) {
            // host IP address exists in database
            return new HostResponse(ErrorCode.OK);
        }
        return new HostResponse(ErrorCode.AS_HOST_NOT_FOUND);
    } catch (ASException e) {
        throw e;
    } catch (Exception e) {
        throw new ASException(e);
    }
}
Also used : TblHostsJpaController(com.intel.mtwilson.as.controller.TblHostsJpaController) TblHosts(com.intel.mtwilson.as.data.TblHosts) ASException(com.intel.mountwilson.as.common.ASException) 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)

Example 35 with TblHosts

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

the class HostBO method queryForHosts.

/**
         * Author: Sudhir
         * 
         * Searches for the hosts using the criteria specified.
         * 
         * @param searchCriteria: If in case the user has not provided any search criteria, then all the hosts
         * would be returned back to the caller
         * @return 
         */
public List<TxtHostRecord> queryForHosts(String searchCriteria) {
    try {
        TblHostsJpaController tblHostsJpaController = new TblHostsJpaController(getEntityManagerFactory());
        List<TxtHostRecord> txtHostList = new ArrayList<TxtHostRecord>();
        List<TblHosts> tblHostList;
        if (searchCriteria != null && !searchCriteria.isEmpty()) {
            log.info("searchCriteria is not null -- calling tblHostsJpaController.findHostsByNameSearchCriteria(searchCriteria)");
            tblHostList = tblHostsJpaController.findHostsByNameSearchCriteria(searchCriteria);
            log.info(new Integer(tblHostList.size()).toString());
        } else {
            log.info("calling tblHostsJpaController.findTblHostsEntities()");
            tblHostList = tblHostsJpaController.findTblHostsEntities();
            log.info(new Integer(tblHostList.size()).toString());
        }
        //			if (tblHostList != null) {
        log.info(String.format("Found [%d] host results for search criteria [%s]", tblHostList.size(), searchCriteria));
        for (TblHosts tblHosts : tblHostList) {
            TxtHostRecord hostObj = createTxtHostFromDatabaseRecord(tblHosts);
            txtHostList.add(hostObj);
        }
        return txtHostList;
    } catch (ASException e) {
        throw e;
    } catch (CryptographyException e) {
        throw new ASException(e, ErrorCode.AS_ENCRYPTION_ERROR, e.getCause() == null ? e.getMessage() : e.getCause().getMessage());
    } catch (Exception e) {
        throw new ASException(e);
    }
}
Also used : TblHostsJpaController(com.intel.mtwilson.as.controller.TblHostsJpaController) CryptographyException(com.intel.mtwilson.crypto.CryptographyException) TblHosts(com.intel.mtwilson.as.data.TblHosts) ArrayList(java.util.ArrayList) ASException(com.intel.mountwilson.as.common.ASException) 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)

Aggregations

TblHosts (com.intel.mtwilson.as.data.TblHosts)42 ASException (com.intel.mountwilson.as.common.ASException)17 CryptographyException (com.intel.mtwilson.crypto.CryptographyException)15 EntityManager (javax.persistence.EntityManager)14 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)13 IOException (java.io.IOException)12 UnknownHostException (java.net.UnknownHostException)11 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)10 ArrayList (java.util.ArrayList)10 TblMle (com.intel.mtwilson.as.data.TblMle)9 TblPcrManifest (com.intel.mtwilson.as.data.TblPcrManifest)9 NoResultException (javax.persistence.NoResultException)8 TblHostsJpaController (com.intel.mtwilson.as.controller.TblHostsJpaController)7 TblTaLog (com.intel.mtwilson.as.data.TblTaLog)6 EntityNotFoundException (javax.persistence.EntityNotFoundException)6 Query (javax.persistence.Query)6 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)6 Hostname (com.intel.mtwilson.util.net.Hostname)5 Matchers.anyString (org.mockito.Matchers.anyString)5 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)4