Search in sources :

Example 6 with TblHostsJpaController

use of com.intel.mtwilson.as.controller.TblHostsJpaController 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)

Example 7 with TblHostsJpaController

use of com.intel.mtwilson.as.controller.TblHostsJpaController in project OpenAttestation by OpenAttestation.

the class HostBO method saveHostInDatabase.

private void saveHostInDatabase(TblHosts newRecordWithTlsPolicyAndKeystore, TxtHost host, String certificate, String location, HashMap<String, ? extends IManifest> pcrMap, List<TblHostSpecificManifest> tblHostSpecificManifests, TblMle biosMleId, TblMle vmmMleId) throws CryptographyException, IOException {
    // Building objects and validating that manifests are created ahead of create of host
    // new TblHosts();
    TblHosts tblHosts = newRecordWithTlsPolicyAndKeystore;
    log.info("saveHostInDatabase with tls policy {} and keystore size {}", tblHosts.getTlsPolicyName(), tblHosts.getTlsKeystore() == null ? "null" : tblHosts.getTlsKeystore().length);
    log.error("saveHostInDatabase with tls policy {} and keystore size {}", tblHosts.getTlsPolicyName(), tblHosts.getTlsKeystore() == null ? "null" : tblHosts.getTlsKeystore().length);
    TblHostsJpaController hostController = getHostsJpaController();
    tblHosts.setAddOnConnectionInfo(host.getAddOn_Connection_String());
    tblHosts.setBiosMleId(biosMleId);
    tblHosts.setDescription(host.getDescription());
    tblHosts.setEmail(host.getEmail());
    if (host.getIPAddress() != null) {
        // datatype.IPAddress
        tblHosts.setIPAddress(host.getIPAddress().toString());
    }
    // datatype.Hostname
    tblHosts.setName(host.getHostName().toString());
    if (host.getPort() != null) {
        tblHosts.setPort(host.getPort());
    }
    tblHosts.setVmmMleId(vmmMleId);
    // null is ok
    tblHosts.setAIKCertificate(certificate);
    if (location != null) {
        tblHosts.setLocation(location);
    }
    tblHosts.setBios_mle_uuid_hex(biosMleId.getUuid_hex());
    tblHosts.setVmm_mle_uuid_hex(vmmMleId.getUuid_hex());
    tblHosts.setUuid_hex(new UUID().toString());
    // create the host
    log.debug("COMMITING NEW HOST DO DATABASE");
    hostController.create(tblHosts);
    log.debug("Save host specific manifest if any");
    createHostSpecificManifest(tblHostSpecificManifests, tblHosts);
}
Also used : TblHostsJpaController(com.intel.mtwilson.as.controller.TblHostsJpaController) TblHosts(com.intel.mtwilson.as.data.TblHosts) UUID(com.intel.mtwilson.util.io.UUID)

Aggregations

TblHostsJpaController (com.intel.mtwilson.as.controller.TblHostsJpaController)7 TblHosts (com.intel.mtwilson.as.data.TblHosts)7 ASException (com.intel.mountwilson.as.common.ASException)5 UnknownHostException (java.net.UnknownHostException)4 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)3 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)3 CryptographyException (com.intel.mtwilson.crypto.CryptographyException)3 IOException (java.io.IOException)3 NoResultException (javax.persistence.NoResultException)3 ArrayList (java.util.ArrayList)2 MwAssetTagCertificateJpaController (com.intel.mtwilson.as.controller.MwAssetTagCertificateJpaController)1 MwAssetTagCertificate (com.intel.mtwilson.as.data.MwAssetTagCertificate)1 AssetTagCertAssociateRequest (com.intel.mtwilson.datatypes.AssetTagCertAssociateRequest)1 UUID (com.intel.mtwilson.util.io.UUID)1 InetAddress (java.net.InetAddress)1