Search in sources :

Example 1 with XXAsset

use of org.apache.ranger.entity.XXAsset in project ranger by apache.

the class TestRangerBizUtil method testGetMObject.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testGetMObject() {
    BaseDao baseDao = Mockito.mock(BaseDao.class);
    Mockito.when(daoManager.getDaoForClassType(RangerCommonEnums.CLASS_TYPE_USER_PROFILE)).thenReturn(baseDao);
    Mockito.when(baseDao.getById(id)).thenReturn(new XXAsset());
    XXDBBase mObjChk = rangerBizUtil.getMObject(RangerCommonEnums.CLASS_TYPE_USER_PROFILE, id);
    Assert.assertNotNull(mObjChk);
}
Also used : BaseDao(org.apache.ranger.common.db.BaseDao) XXAsset(org.apache.ranger.entity.XXAsset) XXDBBase(org.apache.ranger.entity.XXDBBase) Test(org.junit.Test)

Example 2 with XXAsset

use of org.apache.ranger.entity.XXAsset in project ranger by apache.

the class TestRangerBizUtil method testGetDisplayName_MoreThanMaxLen.

@Test
public void testGetDisplayName_MoreThanMaxLen() {
    XXAsset obj = new XXAsset();
    String name = resourceName;
    for (int i = 0; i < 16; i++) {
        name = name + "_" + name + "1";
    }
    obj.setDescription(name);
    String displayNameChk = rangerBizUtil.getDisplayName(obj);
    Assert.assertEquals(displayNameChk.length(), 150);
}
Also used : XXAsset(org.apache.ranger.entity.XXAsset) Test(org.junit.Test)

Example 3 with XXAsset

use of org.apache.ranger.entity.XXAsset in project ranger by apache.

the class PatchMigration_J10002 method migrateServicesToNewSchema.

public void migrateServicesToNewSchema() throws Exception {
    logger.info("==> MigrationPatch.migrateServicesToNewSchema()");
    try {
        List<XXAsset> repoList = daoMgr.getXXAsset().getAll();
        if (repoList.isEmpty()) {
            return;
        }
        if (!repoList.isEmpty()) {
            EmbeddedServiceDefsUtil.instance().init(svcDBStore);
        }
        svcDBStore.setPopulateExistingBaseFields(true);
        for (XXAsset xAsset : repoList) {
            if (xAsset.getActiveStatus() == AppConstants.STATUS_DELETED) {
                continue;
            }
            RangerService existing = svcDBStore.getServiceByName(xAsset.getName());
            if (existing != null) {
                logger.info("Repository/Service already exists. Ignoring migration of repo: " + xAsset.getName());
                continue;
            }
            RangerService service = new RangerService();
            service = mapXAssetToService(service, xAsset);
            service = svcDBStore.createService(service);
            serviceCounter++;
            logger.info("New Service created. ServiceName: " + service.getName());
        }
        svcDBStore.setPopulateExistingBaseFields(false);
    } catch (Exception e) {
        throw new Exception("Error while migrating data to new Plugin Schema.", e);
    }
    logger.info("<== MigrationPatch.migrateServicesToNewSchema()");
}
Also used : XXAsset(org.apache.ranger.entity.XXAsset) RangerService(org.apache.ranger.plugin.model.RangerService)

Example 4 with XXAsset

use of org.apache.ranger.entity.XXAsset in project ranger by apache.

the class PatchMigration_J10002 method migratePoliciesToNewSchema.

public void migratePoliciesToNewSchema() throws Exception {
    logger.info("==> MigrationPatch.migratePoliciesToNewSchema()");
    try {
        List<XXResource> resList = daoMgr.getXXResource().getAll();
        if (resList.isEmpty()) {
            return;
        }
        svcDBStore.setPopulateExistingBaseFields(true);
        for (XXResource xRes : resList) {
            if (xRes.getResourceStatus() == AppConstants.STATUS_DELETED) {
                continue;
            }
            XXAsset xAsset = daoMgr.getXXAsset().getById(xRes.getAssetId());
            if (xAsset == null) {
                logger.error("No Repository found for policyName: " + xRes.getPolicyName());
                continue;
            }
            RangerService service = svcDBStore.getServiceByName(xAsset.getName());
            if (service == null) {
                logger.error("No Service found for policy. Ignoring migration of such policy, policyName: " + xRes.getPolicyName());
                continue;
            }
            XXPolicy existing = daoMgr.getXXPolicy().findByNameAndServiceId(xRes.getPolicyName(), service.getId());
            if (existing != null) {
                logger.info("Policy already exists. Ignoring migration of policy: " + existing.getName());
                continue;
            }
            RangerPolicy policy = new RangerPolicy();
            policy = mapXResourceToPolicy(policy, xRes, service);
            if (policy != null) {
                policy = svcDBStore.createPolicy(policy);
                policyCounter++;
                logger.info("New policy created. policyName: " + policy.getName());
            }
        }
        svcDBStore.setPopulateExistingBaseFields(false);
    } catch (Exception e) {
        throw new Exception("Error while migrating data to new Plugin Schema.", e);
    }
    logger.info("<== MigrationPatch.migratePoliciesToNewSchema()");
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXResource(org.apache.ranger.entity.XXResource) XXAsset(org.apache.ranger.entity.XXAsset) RangerService(org.apache.ranger.plugin.model.RangerService) XXPolicy(org.apache.ranger.entity.XXPolicy)

Example 5 with XXAsset

use of org.apache.ranger.entity.XXAsset in project ranger by apache.

the class PatchPasswordEncryption_J10001 method encryptLookupUserPassword.

private void encryptLookupUserPassword() {
    List<XXAsset> xAssetList = xaDaoManager.getXXAsset().getAll();
    String oldConfig = null;
    String newConfig = null;
    for (XXAsset xAsset : xAssetList) {
        oldConfig = null;
        newConfig = null;
        oldConfig = xAsset.getConfig();
        if (!stringUtil.isEmpty(oldConfig)) {
            newConfig = xAssetService.getConfigWithEncryptedPassword(oldConfig, false);
            xAsset.setConfig(newConfig);
            xaDaoManager.getXXAsset().update(xAsset);
        }
        lineCount++;
        logger.info("Lookup Password updated for Asset : " + xAsset.getName());
        logger.info("oldconfig : " + oldConfig);
        logger.info("newConfig : " + newConfig);
        print(lineCount, "Total updated assets count : ");
    }
}
Also used : XXAsset(org.apache.ranger.entity.XXAsset)

Aggregations

XXAsset (org.apache.ranger.entity.XXAsset)18 Test (org.junit.Test)7 XXResource (org.apache.ranger.entity.XXResource)4 ArrayList (java.util.ArrayList)3 BaseDao (org.apache.ranger.common.db.BaseDao)2 XXDBBase (org.apache.ranger.entity.XXDBBase)2 RangerService (org.apache.ranger.plugin.model.RangerService)2 VXAsset (org.apache.ranger.view.VXAsset)2 VXResource (org.apache.ranger.view.VXResource)2 VXResponse (org.apache.ranger.view.VXResponse)2 Field (java.lang.reflect.Field)1 Date (java.util.Date)1 List (java.util.List)1 SearchCriteria (org.apache.ranger.common.SearchCriteria)1 SearchField (org.apache.ranger.common.SearchField)1 SortField (org.apache.ranger.common.SortField)1 VTrxLogAttr (org.apache.ranger.common.view.VTrxLogAttr)1 XXAssetDao (org.apache.ranger.db.XXAssetDao)1 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)1 XXResourceDao (org.apache.ranger.db.XXResourceDao)1