Skip to content

Commit

Permalink
ServiceNow Batch Source GA Release changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
vikasrathee-cs authored and AnkitCLI committed Oct 9, 2023
1 parent ed1e584 commit 74af16a
Show file tree
Hide file tree
Showing 51 changed files with 810 additions and 668 deletions.
33 changes: 17 additions & 16 deletions docs/ServiceNow-batchsource.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,21 @@ ignored if the Mode is set to `Reporting`.
Data Types Mapping
----------

| ServiceNow Data Type | CDAP Schema Data Type | Comment |
| ------------------------------ | --------------------- | -------------------------------------------------- |
| decimal | double | |
| integer | int | |
| boolean | boolean | |
| reference | string | |
| currency | string | |
| glide_date | string | |
| glide_date_time | string | |
| sys_class_name | string | |
| domain_id | string | |
| domain_path | string | |
| guid | string | |
| translated_html | string | |
| journal | string | |
| string | string | |
| ServiceNow Data Type | CDAP Schema Data Type
| ------------------------------ | ---------------------
| decimal | double
| integer | int
| boolean | boolean
| reference | string
| currency | string
| glide_date | date
| glide_date_time | datetime
| glide_time | time
| sys_class_name | string
| domain_id | string
| domain_path | string
| guid | string
| translated_html | string
| journal | string
| string | string

Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ Feature: ServiceNow Multi Source - Design time validation scenarios
And Click on the Validate button
Then Verify mandatory property error for below listed properties:
| referenceName |
| clientId |
| clientSecret |
| restApiEndpoint |
| user |
| password |

@TS-SN-MULTI-DSGN-ERROR-02
Scenario: Verify validation message for invalid table name
Expand All @@ -41,7 +36,7 @@ Feature: ServiceNow Multi Source - Design time validation scenarios
| INVALID_TABLE |
And fill Credentials section for pipeline user
And Click on the Validate button
Then Verify that the Plugin is displaying an error message: "invalid.property.tablename" on the header
Then Verify that the Plugin Property: "tableNames" is displaying an in-line error message: "invalid.property.tablename"

@TS-SN-MULTI-DSGN-ERROR-03
Scenario: Verify validation message for Start date and End date in invalid format
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ Feature: ServiceNow Multi Source - Design time scenarios (macro)
And Click on the Macro button of Property: "restApiEndpoint" and set the value to: "restApiEndpoint"
And Click on the Macro button of Property: "user" and set the value to: "username"
And Click on the Macro button of Property: "password" and set the value to: "password"
Then Validate "ServiceNow Multi Source" plugin properties
Then Validate "ServiceNow Multi Source" plugin properties
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,4 @@ Feature: ServiceNow Multi Source - Run time scenarios (macro)
And Verify the pipeline status is "Failed"
Then Open Pipeline logs and verify Log entries having below listed Level and Message:
| Level | Message |
| ERROR | invalid.filters.logsmessage |
| ERROR | invalid.filters.logsmessage |
2 changes: 1 addition & 1 deletion src/e2e-test/features/servicenowsink/DesignTime.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@ServiceNow
@SNSink
@Smoke
@Regression
@RegressionSkip
Feature: ServiceNow Sink - Design time scenarios

@TS-SN-DSGN-SINK-01 @BQ_SOURCE_TEST_RECEIVING_SLIP_LINE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@ServiceNow
@SNSink
@Smoke
@Regression
@RegressionSkip
Feature: ServiceNow Sink - Design time validation scenarios

@TS-SN-DSGN-SINK-ERROR-01
Expand Down Expand Up @@ -60,4 +60,4 @@ Feature: ServiceNow Sink - Design time validation scenarios
And Enter input plugin property: "name" with value: "connection.name"
And fill Credentials section with invalid credentials
Then Click on the Test Connection button
Then Verify the invalid connection error message: "invalid.testconnection.logmessage" on the footer
Then Verify the invalid connection error message: "invalid.testconnection.logmessage" on the footer
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@ServiceNow
@SNSink
@Smoke
@@Regression
@@RegressionSkip
Feature: ServiceNow Sink - Design time validation scenarios (macro)

@TS-SN-DSGN-SINK-MACRO-01 @BQ_SOURCE_TEST_RECEIVING_SLIP_LINE
Expand Down Expand Up @@ -69,4 +69,4 @@ Feature: ServiceNow Sink - Design time validation scenarios (macro)
And fill Credentials section for pipeline user
And Enter input plugin property: "tableName" with value: "receiving_slip_line"
And Click on the Macro button of Property: "operation" and set the value to: "operation"
Then Validate "ServiceNow" plugin properties
Then Validate "ServiceNow" plugin properties
2 changes: 1 addition & 1 deletion src/e2e-test/features/servicenowsink/RunTime.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@ServiceNow
@SNSink
@Smoke
@Regression
@RegressionSkip
Feature: ServiceNow Sink - Run time scenarios

@TS-SN-RNTM-SINK-01 @BQ_SOURCE_TEST_RECEIVING_SLIP_LINE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@ServiceNow
@SNSink
@Smoke
@Regression
@RegressionSkip
Feature: ServiceNow Sink - Run time scenarios (macro)

@TS-SN-RNTM-SINK-MACRO-01 @BQ_SOURCE_TEST_RECEIVING_SLIP_LINE @BQ_SINK_CLEANUP
Expand Down Expand Up @@ -197,4 +197,3 @@ Feature: ServiceNow Sink - Run time scenarios (macro)
Then Open Pipeline logs and verify Log entries having below listed Level and Message:
| Level | Message |
| ERROR | invalid.credentials.logsmessage |

Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ Feature: ServiceNow Source - Design time validation scenarios
And Click on the Validate button
Then Verify mandatory property error for below listed properties:
| referenceName |
| clientId |
| clientSecret |
| restApiEndpoint |
| user |
| password |

@TS-SN-DSGN-ERROR-02
Scenario: Verify invalid credentials validation messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ Feature: ServiceNow Source - Design time scenarios (macro)
And Click on the Macro button of Property: "restApiEndpoint" and set the value to: "restApiEndpoint"
And Click on the Macro button of Property: "user" and set the value to: "username"
And Click on the Macro button of Property: "password" and set the value to: "password"
Then Validate "ServiceNow" plugin properties
Then Validate "ServiceNow" plugin properties
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,4 @@ Feature: ServiceNow Source - Run time scenarios (macro)
And Verify the pipeline status is "Failed"
Then Open Pipeline logs and verify Log entries having below listed Level and Message:
| Level | Message |
| ERROR | invalid.filters.logsmessage |
| ERROR | invalid.filters.logsmessage |
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void configureBqSinkPlugin() {
public void configureBqMultiTableSinkPlugin() {
String referenceName = "Test" + RandomStringUtils.randomAlphanumeric(10);
CdfBigQueryPropertiesActions.enterBigQueryReferenceName(referenceName);
CdfBigQueryPropertiesActions.enterBigQueryDataset(PluginPropertyUtils.pluginProp("bq.target.dataset"));
CdfBigQueryPropertiesActions.enterBigQueryDataset(PluginPropertyUtils.pluginProp("bq.target.dataset2"));
}

@Then("Verify count of no of records transferred to the target BigQuery Table")
Expand Down
2 changes: 1 addition & 1 deletion src/e2e-test/resources/errorMessage.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ validationSuccessMessage=No errors found.
#Invalid value
invalid.property.tablename=Bad Request. Table:
invalid.property.startdate=Invalid format for Start date. Correct Format: yyyy-MM-dd
invalid.property.enddate=Invalid format for End date. Correct Format:yyyy-MM-dd
invalid.property.enddate=Invalid format for End date. Correct Format: yyyy-MM-dd
invalid.property.credentials=Unable to connect to ServiceNow Instance. Ensure properties like Client ID, Client Secret, API Endpoint, User Name, Password are correct.

#Logs error message
Expand Down
20 changes: 11 additions & 9 deletions src/e2e-test/resources/pluginParameters.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pipeline.user.password = SERVICE_NOW_PASSWORD

#Tables
receiving_slip_line=proc_rec_slip_item
asset_covered=clm_m2m_contract_asset
agent_assist_recommendation = agent_assist_recommendation
vendor_catalog_item = pc_vendor_cat_item
service_offering = service_offering
Expand Down Expand Up @@ -38,26 +39,27 @@ connection.name = dummy
projectId=cdf-athena
datasetprojectId=cdf-athena
bq.target.dataset=SN_test_automation
bq.target.dataset2=SN_Test_atm

##ServiceNowSink
INSERT=insert
UPDATE=update
pagesize=200

##ExpectedSchemaJSONs
schema.table.receiving.slip.line=[{"key":"cost","value":"string"},{"key":"quantity","value":"string"},\
{"key":"purchase_line","value":"string"},{"key":"sys_mod_count","value":"string"},\
{"key":"received","value":"string"},{"key":"requested_for","value":"string"},\
{"key":"sys_updated_on","value":"string"},{"key":"sys_tags","value":"string"},{"key":"number","value":"string"},\
schema.table.receiving.slip.line=[{"key":"quantity","value":"int"},{"key":"cost","value":"string"},\
{"key":"purchase_line","value":"string"},{"key":"sys_mod_count","value":"int"},\
{"key":"received","value":"datetime"},{"key":"requested_for","value":"string"},\
{"key":"sys_updated_on","value":"datetime"},{"key":"sys_tags","value":"string"},{"key":"number","value":"string"},\
{"key":"sys_id","value":"string"},{"key":"received_by","value":"string"},{"key":"sys_updated_by","value":"string"},\
{"key":"receiving_slip","value":"string"},{"key":"sys_created_on","value":"string"},\
{"key":"receiving_slip","value":"string"},{"key":"sys_created_on","value":"datetime"},\
{"key":"sys_domain","value":"string"},{"key":"sys_created_by","value":"string"}]

schema.table.asset.covered=[{"key":"added","value":"string"},{"key":"contract","value":"string"},\
{"key":"sys_mod_count","value":"string"},{"key":"sys_updated_on","value":"string"},\
schema.table.asset.covered=[{"key":"added","value":"date"},{"key":"contract","value":"string"},\
{"key":"sys_mod_count","value":"int"},{"key":"sys_updated_on","value":"datetime"},\
{"key":"sys_domain_path","value":"string"},{"key":"sys_tags","value":"string"},\
{"key":"sys_id","value":"string"},{"key":"sys_updated_by","value":"string"},{"key":"removed","value":"string"},\
{"key":"sys_created_on","value":"string"},{"key":"sys_domain","value":"string"},{"key":"asset","value":"string"},\
{"key":"sys_id","value":"string"},{"key":"sys_updated_by","value":"string"},{"key":"removed","value":"date"},\
{"key":"sys_created_on","value":"datetime"},{"key":"sys_domain","value":"string"},{"key":"asset","value":"string"},\
{"key":"sys_created_by","value":"string"}]

schema.table.condition=[{"key":"condition_check","value":"string"},{"key":"sys_mod_count","value":"string"},\
Expand Down
28 changes: 13 additions & 15 deletions src/main/java/io/cdap/plugin/servicenow/ServiceNowBaseConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
import io.cdap.cdap.api.plugin.PluginConfig;
import io.cdap.cdap.etl.api.FailureCollector;
import io.cdap.plugin.common.ConfigUtil;
import io.cdap.plugin.common.IdUtils;
import io.cdap.plugin.servicenow.apiclient.ServiceNowTableAPIClientImpl;
import io.cdap.plugin.servicenow.apiclient.ServiceNowTableAPIRequestBuilder;
import io.cdap.plugin.servicenow.connector.ServiceNowConnectorConfig;
import io.cdap.plugin.servicenow.restapi.RestAPIResponse;
import io.cdap.plugin.servicenow.source.ServiceNowSourceConfig;
import io.cdap.plugin.servicenow.util.ServiceNowConstants;
import io.cdap.plugin.servicenow.util.SourceValueType;
import io.cdap.plugin.servicenow.util.Util;
import org.apache.http.HttpStatus;
import org.apache.oltu.oauth2.common.exception.OAuthProblemException;
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
Expand All @@ -52,18 +50,17 @@ public class ServiceNowBaseConfig extends PluginConfig {
@Macro
@Nullable
@Description("The existing connection to use.")
private ServiceNowConnectorConfig connection;

@Nullable
public ServiceNowConnectorConfig getConnection() {
return connection;
}
private final ServiceNowConnectorConfig connection;

public ServiceNowBaseConfig(String clientId, String clientSecret, String restApiEndpoint,
String user, String password) {
this.connection = new ServiceNowConnectorConfig(clientId, clientSecret, restApiEndpoint, user, password);
}

@Nullable
public ServiceNowConnectorConfig getConnection() {
return connection;
}

/**
* Validates {@link ServiceNowSourceConfig} instance.
Expand All @@ -81,16 +78,16 @@ public void validateCredentials(FailureCollector collector) {
validateServiceNowConnection(collector);
}
}

@VisibleForTesting
public void validateServiceNowConnection(FailureCollector collector) {
try {
ServiceNowTableAPIClientImpl restApi = new ServiceNowTableAPIClientImpl(connection);
restApi.getAccessToken();
} catch (Exception e) {
collector.addFailure("Unable to connect to ServiceNow Instance.",
"Ensure properties like Client ID, Client Secret, API Endpoint, User Name, Password " +
"are correct.")
"Ensure properties like Client ID, Client Secret, API Endpoint, User Name, Password " +
"are correct.")
.withConfigProperty(ServiceNowConstants.PROPERTY_CLIENT_ID)
.withConfigProperty(ServiceNowConstants.PROPERTY_CLIENT_SECRET)
.withConfigProperty(ServiceNowConstants.PROPERTY_API_ENDPOINT)
Expand Down Expand Up @@ -121,7 +118,8 @@ && shouldConnect()
&& !containsMacro(ServiceNowConstants.PROPERTY_VALUE_TYPE);
}

public void validateTable(String tableName, SourceValueType valueType, FailureCollector collector) {
public void validateTable(String tableName, SourceValueType valueType, FailureCollector collector,
String tableField) {
// Call API to fetch first record from the table
ServiceNowTableAPIRequestBuilder requestBuilder = new ServiceNowTableAPIRequestBuilder(
connection.getRestApiEndpoint(), tableName, false)
Expand All @@ -142,11 +140,11 @@ public void validateTable(String tableName, SourceValueType valueType, FailureCo
if (!apiResponse.isSuccess()) {
if (apiResponse.getHttpStatus() == HttpStatus.SC_BAD_REQUEST) {
collector.addFailure("Bad Request. Table: " + tableName + " is invalid.", "")
.withConfigProperty(ServiceNowConstants.PROPERTY_TABLE_NAME);
.withConfigProperty(tableField);
}
} else if (serviceNowTableAPIClient.parseResponseToResultListOfMap(apiResponse.getResponseBody()).isEmpty()) {
collector.addFailure("Table: " + tableName + " is empty.", "")
.withConfigProperty(ServiceNowConstants.PROPERTY_TABLE_NAME);
// Removed config property as in case of MultiSource, only first table error was populating.
collector.addFailure("Table: " + tableName + " is empty.", "");
}
} catch (OAuthSystemException | OAuthProblemException e) {
collector.addFailure("Unable to connect to ServiceNow Instance.",
Expand Down
Loading

0 comments on commit 74af16a

Please sign in to comment.