Search in sources :

Example 26 with TblMle

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

the class MleBO method updateMle.

/**
    * 
    * @param mleData
    * @return 
    */
public String updateMle(MleData mleData) {
    try {
        TblMle tblMle = getMleDetails(mleData.getName(), mleData.getVersion(), mleData.getOsName(), mleData.getOsVersion(), mleData.getOemName());
        if (tblMle == null && mleData.getOemName() != null) {
            throw new ASException(ErrorCode.WS_MLE_OEM_DOES_NOT_EXIST, mleData.getName(), mleData.getVersion(), mleData.getOemName());
        }
        if (tblMle == null && mleData.getOsName() != null) {
            throw new ASException(ErrorCode.WS_MLE_OS_DOES_NOT_EXIST, mleData.getName(), mleData.getVersion(), mleData.getOsName(), mleData.getOsVersion());
        }
        setTblMle(tblMle, mleData);
        mleJpaController.edit(tblMle);
        updatePcrManifest(tblMle, mleData);
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        new ASException(e);
    }
    return "true";
}
Also used : TblMle(com.intel.mtwilson.as.data.TblMle) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) NoResultException(javax.persistence.NoResultException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)

Example 27 with TblMle

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

the class MleBO method addMLe.

/**
	 * For VMM, the OS Name and OS Version in the new MLE must ALREADY be in the
	 * database, or this method will throw an error.
	 * 
	 * @param mleData
	 * @return
	 */
public String addMLe(MleData mleData, String mleUuid) {
    String osOemUuid = null;
    try {
        TblMle tblMle = getMleDetails(mleData.getName(), mleData.getVersion(), mleData.getOsName(), mleData.getOsVersion(), mleData.getOemName());
        if (tblMle != null) {
            throw new ASException(ErrorCode.WS_MLE_ALREADY_EXISTS, mleData.getName());
        }
        if (mleData.getName().toUpperCase().contains("ESX")) {
            String version = getUpperCase(mleData.getVersion()).substring(0, 2);
            if (!version.equals("51") && !version.equals("50")) {
                throw new ASException(ErrorCode.WS_ESX_MLE_NOT_SUPPORTED);
            }
        }
        if (mleData.getMleType().equals("VMM")) {
            TblOs osObj = new TblOsJpaController(getEntityManagerFactory()).findTblOsByNameVersion(mleData.getOsName(), mleData.getOsVersion());
            //TblOs osObj = My.jpa().mwOs().findTblOsByNameVersion(mleData.getOsName(), mleData.getOsVersion());
            osOemUuid = osObj.getUuid_hex();
        } else if (mleData.getMleType().equals("BIOS")) {
            TblOem oemObj = new TblOemJpaController(getEntityManagerFactory()).findTblOemByName(mleData.getOemName());
            //TblOem oemObj = My.jpa().mwOem().findTblOemByName(mleData.getOemName());
            osOemUuid = oemObj.getUuid_hex();
        }
        /*
             if (mleData.getMleType().equalsIgnoreCase("BIOS")){
                 if (mleData.getManifestList() != null){
                     for (ManifestData manifestData : mleData.getManifestList()) {
                         if (Integer.valueOf(manifestData.getName()).intValue() > 5 || Integer.valueOf(manifestData.getName()).intValue() < 0) {
                             throw new ASException(ErrorCode.WS_MLE_PCR_NOT_VALID, manifestData.getName());
                         }
                     }
                 }
             }
             
             if (mleData.getMleType().equalsIgnoreCase("VMM")){
                 if (mleData.getManifestList() != null){
                     for (ManifestData manifestData : mleData.getManifestList()) {
                         if (Integer.valueOf(manifestData.getName()).intValue() > 20 || Integer.valueOf(manifestData.getName()).intValue() < 17) {
                             throw new ASException(ErrorCode.WS_MLE_PCR_NOT_VALID, manifestData.getName());
                         }
                     }
                 }
             }*/
        tblMle = getTblMle(mleData, mleUuid, osOemUuid);
        mleJpaController.create(tblMle);
        addPcrManifest(tblMle, mleData.getManifestList());
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return "true";
}
Also used : TblOsJpaController(com.intel.mtwilson.as.controller.TblOsJpaController) TblOemJpaController(com.intel.mtwilson.as.controller.TblOemJpaController) TblMle(com.intel.mtwilson.as.data.TblMle) TblOem(com.intel.mtwilson.as.data.TblOem) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) NoResultException(javax.persistence.NoResultException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException) TblOs(com.intel.mtwilson.as.data.TblOs)

Example 28 with TblMle

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

the class MleBO method findMle.

/**
    * 
    * @param mleName
    * @param mleVersion
    * @param osName
    * @param osVersion
    * @param oemName
    * @return 
    */
public MleData findMle(String mleName, String mleVersion, String osName, String osVersion, String oemName) {
    try {
        TblMle tblMle = getMleDetails(mleName, mleVersion, osName, osVersion, oemName);
        if (tblMle == null) {
            throw new ASException(ErrorCode.WS_MLE_DOES_NOT_EXIST, mleName, mleVersion);
        }
        MleData mleData = createMleDataFromDatabaseRecord(tblMle, true);
        return mleData;
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
}
Also used : TblMle(com.intel.mtwilson.as.data.TblMle) MleData(com.intel.mtwilson.datatypes.MleData) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) NoResultException(javax.persistence.NoResultException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)

Example 29 with TblMle

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

the class MleBO method updatePCRWhiteList.

/**
         * Added By: Sudhir on June 20, 2012
         * 
         * Processes the update request for an existing PCR white list for the specified MLE.
         * 
         * @param pcrData: White list data sent by the user
         * @return : true if the call is successful or else exception.
         */
public String updatePCRWhiteList(PCRWhiteList pcrData) {
    TblMle tblMle;
    TblPcrManifest tblPcr;
    try {
        tblMle = getMleDetails(pcrData.getMleName(), pcrData.getMleVersion(), pcrData.getOsName(), pcrData.getOsVersion(), pcrData.getOemName());
        if (tblMle == null && pcrData.getOemName() != null) {
            throw new ASException(ErrorCode.WS_MLE_OEM_DOES_NOT_EXIST, pcrData.getMleName(), pcrData.getMleVersion(), pcrData.getOemName());
        }
        if (tblMle == null && pcrData.getOsName() != null) {
            throw new ASException(ErrorCode.WS_MLE_OS_DOES_NOT_EXIST, pcrData.getMleName(), pcrData.getMleVersion(), pcrData.getOsName(), pcrData.getOsVersion());
        }
        // Now we need to check if PCR is already configured. If yes, then
        // we ned to ask the user to use the Update option instead of create
        tblPcr = getPCRWhiteListDetails(tblMle.getId(), pcrData.getPcrName());
        if (tblPcr == null) {
            throw new ASException(ErrorCode.WS_PCR_WHITELIST_DOES_NOT_EXIST, pcrData.getPcrName());
        }
        // Now update the pcr in the database.
        tblPcr.setValue(pcrData.getPcrDigest());
        pcrManifestJpaController.edit(tblPcr);
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return "true";
}
Also used : TblMle(com.intel.mtwilson.as.data.TblMle) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) NoResultException(javax.persistence.NoResultException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)

Example 30 with TblMle

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

the class OsBO method deleteOs.

/**
     * 
     * @param osName
     * @param osVersion
     * @return 
     */
public String deleteOs(String osName, String osVersion) {
    try {
        TblOs tblOs = tblOsJpaController.findTblOsByNameVersion(osName, osVersion);
        if (tblOs == null) {
            throw new ASException(ErrorCode.WS_OS_DOES_NOT_EXIST, osName, osVersion);
        }
        Collection<TblMle> tblMleCollection = tblOs.getTblMleCollection();
        if (tblMleCollection != null) {
            log.info("OS is currently associated with # MLEs: " + tblMleCollection.size());
            if (!tblMleCollection.isEmpty()) {
                throw new ASException(ErrorCode.WS_OS_ASSOCIATION_EXISTS, osName, osVersion, tblMleCollection.size());
            }
        }
        tblOsJpaController.destroy(tblOs.getId());
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return "true";
}
Also used : TblMle(com.intel.mtwilson.as.data.TblMle) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) TblOs(com.intel.mtwilson.as.data.TblOs)

Aggregations

TblMle (com.intel.mtwilson.as.data.TblMle)65 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)25 ASException (com.intel.mountwilson.as.common.ASException)20 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)20 EntityManager (javax.persistence.EntityManager)20 NoResultException (javax.persistence.NoResultException)19 TblPcrManifest (com.intel.mtwilson.as.data.TblPcrManifest)18 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)17 ArrayList (java.util.ArrayList)16 Matchers.anyString (org.mockito.Matchers.anyString)14 EntityNotFoundException (javax.persistence.EntityNotFoundException)11 TblHosts (com.intel.mtwilson.as.data.TblHosts)9 TblOem (com.intel.mtwilson.as.data.TblOem)9 TblOs (com.intel.mtwilson.as.data.TblOs)9 Query (javax.persistence.Query)8 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)8 Test (org.junit.Test)8 TblMleJpaController (com.intel.mtwilson.as.controller.TblMleJpaController)7 TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)7 MwMleSource (com.intel.mtwilson.as.data.MwMleSource)6