Search in sources :

Example 51 with RangerService

use of org.apache.ranger.plugin.model.RangerService 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 52 with RangerService

use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.

the class AssetREST method getXAsset.

@GET
@Path("/assets/{id}")
@Produces({ "application/xml", "application/json" })
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.GET_X_ASSET + "\")")
public VXAsset getXAsset(@PathParam("id") Long id) {
    if (logger.isDebugEnabled()) {
        logger.debug("==> AssetREST.getXAsset(" + id + ")");
    }
    RangerService service = serviceREST.getService(id);
    VXAsset ret = serviceUtil.toVXAsset(service);
    if (logger.isDebugEnabled()) {
        logger.debug("<== AssetREST.getXAsset(" + id + "): " + ret);
    }
    return ret;
}
Also used : RangerService(org.apache.ranger.plugin.model.RangerService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 53 with RangerService

use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.

the class AssetREST method searchXResources.

@GET
@Path("/resources")
@Produces({ "application/xml", "application/json" })
public VXResourceList searchXResources(@Context HttpServletRequest request) {
    if (logger.isDebugEnabled()) {
        logger.debug("==> AssetREST.searchXResources()");
    }
    VXResourceList ret = new VXResourceList();
    SearchFilter filter = searchUtil.getSearchFilterFromLegacyRequest(request, xResourceService.sortFields);
    List<RangerPolicy> policies = serviceREST.getPolicies(filter);
    if (policies != null) {
        List<VXResource> resources = new ArrayList<VXResource>();
        for (RangerPolicy policy : policies) {
            RangerService service = serviceREST.getServiceByName(policy.getService());
            VXResource resource = serviceUtil.toVXResource(policy, service);
            if (resource != null) {
                resources.add(resource);
            }
        }
        ret.setVXResources(resources);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("<== AssetREST.searchXResources(): count=" + ret.getResultSize());
    }
    return ret;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) ArrayList(java.util.ArrayList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerService(org.apache.ranger.plugin.model.RangerService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 54 with RangerService

use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.

the class AssetREST method createXResource.

@POST
@Path("/resources")
@Produces({ "application/xml", "application/json" })
public VXResource createXResource(VXResource vXResource) {
    if (logger.isDebugEnabled()) {
        logger.debug("==> AssetREST.createXResource(" + vXResource + ")");
    }
    RangerService service = serviceREST.getService(vXResource.getAssetId());
    RangerPolicy policy = serviceUtil.toRangerPolicy(vXResource, service);
    RangerPolicy createdPolicy = serviceREST.createPolicy(policy, null);
    VXResource ret = serviceUtil.toVXResource(createdPolicy, service);
    if (logger.isDebugEnabled()) {
        logger.debug("<== AssetREST.createXResource(" + vXResource + "): " + ret);
    }
    return ret;
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerService(org.apache.ranger.plugin.model.RangerService) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 55 with RangerService

use of org.apache.ranger.plugin.model.RangerService in project ranger by apache.

the class AssetREST method configTest.

@POST
@Path("/assets/testConfig")
@Produces({ "application/xml", "application/json" })
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.TEST_CONFIG + "\")")
public VXResponse configTest(VXAsset vXAsset) {
    if (logger.isDebugEnabled()) {
        logger.debug("==> AssetREST.configTest(" + vXAsset + ")");
    }
    RangerService service = serviceUtil.toRangerService(vXAsset);
    VXResponse ret = serviceREST.validateConfig(service);
    if (logger.isDebugEnabled()) {
        logger.debug("<== AssetREST.testConfig(" + vXAsset + "): " + ret);
    }
    return ret;
}
Also used : RangerService(org.apache.ranger.plugin.model.RangerService) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

RangerService (org.apache.ranger.plugin.model.RangerService)163 Test (org.junit.Test)85 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)52 ArrayList (java.util.ArrayList)39 WebApplicationException (javax.ws.rs.WebApplicationException)30 XXServiceDef (org.apache.ranger.entity.XXServiceDef)26 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)24 VXString (org.apache.ranger.view.VXString)24 XXService (org.apache.ranger.entity.XXService)23 Path (javax.ws.rs.Path)22 Produces (javax.ws.rs.Produces)21 Date (java.util.Date)20 HashMap (java.util.HashMap)16 XXServiceDefDao (org.apache.ranger.db.XXServiceDefDao)16 HttpServletRequest (javax.servlet.http.HttpServletRequest)15 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)14 IOException (java.io.IOException)12 GET (javax.ws.rs.GET)12 XXTrxLog (org.apache.ranger.entity.XXTrxLog)12 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)12