Search in sources :

Example 76 with Error

use of com.google.privacy.dlp.v2.Error in project java-dlp by googleapis.

the class DlpServiceClientTest method createJobTriggerTest2.

@Test
public void createJobTriggerTest2() throws Exception {
    JobTrigger expectedResponse = JobTrigger.newBuilder().setName(JobTriggerName.ofProjectJobTriggerName("[PROJECT]", "[JOB_TRIGGER]").toString()).setDisplayName("displayName1714148973").setDescription("description-1724546052").addAllTriggers(new ArrayList<JobTrigger.Trigger>()).addAllErrors(new ArrayList<Error>()).setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).setLastRunTime(Timestamp.newBuilder().build()).build();
    mockDlpService.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    JobTrigger jobTrigger = JobTrigger.newBuilder().build();
    JobTrigger actualResponse = client.createJobTrigger(parent, jobTrigger);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDlpService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateJobTriggerRequest actualRequest = ((CreateJobTriggerRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(jobTrigger, actualRequest.getJobTrigger());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ProjectName(com.google.privacy.dlp.v2.ProjectName) ArrayList(java.util.ArrayList) Error(com.google.privacy.dlp.v2.Error) JobTrigger(com.google.privacy.dlp.v2.JobTrigger) CreateJobTriggerRequest(com.google.privacy.dlp.v2.CreateJobTriggerRequest) Test(org.junit.Test)

Example 77 with Error

use of com.google.privacy.dlp.v2.Error in project java-dlp by googleapis.

the class DlpServiceClientTest method updateJobTriggerTest2.

@Test
public void updateJobTriggerTest2() throws Exception {
    JobTrigger expectedResponse = JobTrigger.newBuilder().setName(JobTriggerName.ofProjectJobTriggerName("[PROJECT]", "[JOB_TRIGGER]").toString()).setDisplayName("displayName1714148973").setDescription("description-1724546052").addAllTriggers(new ArrayList<JobTrigger.Trigger>()).addAllErrors(new ArrayList<Error>()).setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).setLastRunTime(Timestamp.newBuilder().build()).build();
    mockDlpService.addResponse(expectedResponse);
    String name = "name3373707";
    JobTrigger jobTrigger = JobTrigger.newBuilder().build();
    FieldMask updateMask = FieldMask.newBuilder().build();
    JobTrigger actualResponse = client.updateJobTrigger(name, jobTrigger, updateMask);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDlpService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    UpdateJobTriggerRequest actualRequest = ((UpdateJobTriggerRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertEquals(jobTrigger, actualRequest.getJobTrigger());
    Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) UpdateJobTriggerRequest(com.google.privacy.dlp.v2.UpdateJobTriggerRequest) ArrayList(java.util.ArrayList) Error(com.google.privacy.dlp.v2.Error) ByteString(com.google.protobuf.ByteString) JobTrigger(com.google.privacy.dlp.v2.JobTrigger) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 78 with Error

use of com.google.privacy.dlp.v2.Error in project java-dlp by googleapis.

the class DlpServiceClientTest method getJobTriggerTest2.

@Test
public void getJobTriggerTest2() throws Exception {
    JobTrigger expectedResponse = JobTrigger.newBuilder().setName(JobTriggerName.ofProjectJobTriggerName("[PROJECT]", "[JOB_TRIGGER]").toString()).setDisplayName("displayName1714148973").setDescription("description-1724546052").addAllTriggers(new ArrayList<JobTrigger.Trigger>()).addAllErrors(new ArrayList<Error>()).setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).setLastRunTime(Timestamp.newBuilder().build()).build();
    mockDlpService.addResponse(expectedResponse);
    String name = "name3373707";
    JobTrigger actualResponse = client.getJobTrigger(name);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDlpService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetJobTriggerRequest actualRequest = ((GetJobTriggerRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) Error(com.google.privacy.dlp.v2.Error) GetJobTriggerRequest(com.google.privacy.dlp.v2.GetJobTriggerRequest) ByteString(com.google.protobuf.ByteString) JobTrigger(com.google.privacy.dlp.v2.JobTrigger) Test(org.junit.Test)

Example 79 with Error

use of com.google.privacy.dlp.v2.Error in project java-dlp by googleapis.

the class DlpServiceClientTest method createDlpJobTest5.

@Test
public void createDlpJobTest5() throws Exception {
    DlpJob expectedResponse = DlpJob.newBuilder().setName(DlpJobName.ofProjectDlpJobName("[PROJECT]", "[DLP_JOB]").toString()).setType(DlpJobType.forNumber(0)).setCreateTime(Timestamp.newBuilder().build()).setStartTime(Timestamp.newBuilder().build()).setEndTime(Timestamp.newBuilder().build()).setJobTriggerName("jobTriggerName494333030").addAllErrors(new ArrayList<Error>()).build();
    mockDlpService.addResponse(expectedResponse);
    String parent = "parent-995424086";
    InspectJobConfig inspectJob = InspectJobConfig.newBuilder().build();
    DlpJob actualResponse = client.createDlpJob(parent, inspectJob);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDlpService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateDlpJobRequest actualRequest = ((CreateDlpJobRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertEquals(inspectJob, actualRequest.getInspectJob());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) DlpJob(com.google.privacy.dlp.v2.DlpJob) ByteString(com.google.protobuf.ByteString) CreateDlpJobRequest(com.google.privacy.dlp.v2.CreateDlpJobRequest) InspectJobConfig(com.google.privacy.dlp.v2.InspectJobConfig) Test(org.junit.Test)

Example 80 with Error

use of com.google.privacy.dlp.v2.Error in project bq-pii-classifier by GoogleCloudPlatform.

the class Inspector method execute.

public DlpJob execute(Operation request, String trackingId, String pubSubMessageId) throws IOException, NonRetryableApplicationException {
    logger.logFunctionStart(trackingId);
    logger.logInfoWithTracker(trackingId, String.format("Request : %s", request.toString()));
    /**
     *  Check if we already processed this pubSubMessageId before to avoid submitting BQ queries
     *  in case we have unexpected errors with PubSub re-sending the message. This is an extra measure to avoid unnecessary cost.
     *  We do that by keeping simple flag files in GCS with the pubSubMessageId as file name.
     */
    String flagFileName = String.format("%s/%s", persistentSetObjectPrefix, pubSubMessageId);
    if (persistentSet.contains(flagFileName)) {
        // log error and ACK and return
        String msg = String.format("PubSub message ID '%s' has been processed before by %s. The message should be ACK to PubSub to stop retries. Please investigate further why the message was retried in the first place.", pubSubMessageId, this.getClass().getSimpleName());
        throw new NonRetryableApplicationException(msg);
    }
    // get Table Scan Limits config and Table size
    TableScanLimitsConfig tableScanLimitsConfig = new TableScanLimitsConfig(config.getTableScanLimitsJsonConfig());
    logger.logInfoWithTracker(trackingId, String.format("TableScanLimitsConfig is %s", tableScanLimitsConfig.toString()));
    // DLP job config accepts Integer only for table scan limit. Must downcast
    // NumRows from BigInteger to Integer
    TableSpec targetTableSpec = TableSpec.fromSqlString(request.getEntityKey());
    Integer tableNumRows = bqService.getTableNumRows(targetTableSpec).intValue();
    InspectJobConfig jobConfig = createJob(targetTableSpec, tableScanLimitsConfig, tableNumRows, config);
    CreateDlpJobRequest createDlpJobRequest = CreateDlpJobRequest.newBuilder().setJobId(// Letters, numbers, hyphens, and underscores allowed.
    trackingId).setParent(LocationName.of(config.getProjectId(), config.getRegionId()).toString()).setInspectJob(jobConfig).build();
    DlpJob submittedDlpJob = dlpService.submitJob(createDlpJobRequest);
    logger.logInfoWithTracker(trackingId, String.format("DLP job created successfully id='%s'", submittedDlpJob.getName()));
    // Add a flag key marking that we already completed this request and no additional runs
    // are required in case PubSub is in a loop of retrying due to ACK timeout while the service has already processed the request
    // This is an extra measure to avoid unnecessary cost due to config issues.
    logger.logInfoWithTracker(trackingId, String.format("Persisting processing key for PubSub message ID %s", pubSubMessageId));
    persistentSet.add(flagFileName);
    logger.logFunctionEnd(trackingId);
    return submittedDlpJob;
}
Also used : TableSpec(com.google.cloud.pso.bq_pii_classifier.entities.TableSpec) TableScanLimitsConfig(com.google.cloud.pso.bq_pii_classifier.entities.TableScanLimitsConfig) NonRetryableApplicationException(com.google.cloud.pso.bq_pii_classifier.entities.NonRetryableApplicationException) DlpJob(com.google.privacy.dlp.v2.DlpJob) CreateDlpJobRequest(com.google.privacy.dlp.v2.CreateDlpJobRequest) InspectJobConfig(com.google.privacy.dlp.v2.InspectJobConfig)

Aggregations

ArrayList (java.util.ArrayList)28 DlpServiceClient (com.google.cloud.dlp.v2.DlpServiceClient)23 Test (org.junit.Test)23 ParseException (org.apache.commons.cli.ParseException)18 AbstractMessage (com.google.protobuf.AbstractMessage)16 DlpJob (com.google.privacy.dlp.v2.DlpJob)15 InfoType (com.google.privacy.dlp.v2.InfoType)13 CreateDlpJobRequest (com.google.privacy.dlp.v2.CreateDlpJobRequest)12 ByteString (com.google.protobuf.ByteString)12 Error (dev.hawala.xns.level2.Error)12 Error (org.ovirt.engine.sdk4.Error)12 InspectConfig (com.google.privacy.dlp.v2.InspectConfig)11 Error (org.eclipse.bpmn2.Error)11 ContentItem (com.google.privacy.dlp.v2.ContentItem)10 ProjectName (com.google.privacy.dlp.v2.ProjectName)9 Iterator (java.util.Iterator)9 JobTrigger (com.google.privacy.dlp.v2.JobTrigger)8 RootElement (org.eclipse.bpmn2.RootElement)8 Error (com.google.privacy.dlp.v2.Error)7 ServiceOptions (com.google.cloud.ServiceOptions)6