Skip to content

Commit c30a8d4

Browse files
authored
(fix/refactor): Remove unnecessary calls to Notification APIs (IDETECT-4992) (#1708)
* Notification APIs: remove unnecessary calls * Don't wait at BOM level for IAC or impact analysis scans since we cannot check their completion status via notifications or bom status. This is existing behaviour, setting wait to true was a noop. * Refactor Impact Analysis upload operation to createCodeLocationsWithoutNotificationTaskRange. Prevents call to notifications API for which the results were never used downstream, CodeLocationCreationData's NotificationTaskRange is null. * Latest IntelligentModeStepRunner changes * Pkg mngr and signature updates * Testing for regressions * Remove unused impact analysis related methods * Remove unused ImpactAnalysisToolResult class * Deprecate shouldWaitAtScanLevel since it simply checks if a server version exists and is at least 2023.1.1 which has reached end of service. * Update bd-common version with soon to be released lib version * Propogate removal of shouldWaitAtScanLevel to signature scanner * Remove prescass pkg mngr BDIO code location upload from being considered a waitable (via notifications). * Minor updates * Rename back to uploadBdioFiles * Clean up comments * Revert changes to waitable signature scanner code loctaion * Remove comments in signaturescansteprunner * Add missed method update for binary upload * Remove NotificationTaskRange param from WaitableCodeLocationData constructor as it is no longer used. * Fix whitespace in diff * Fix method rename issue after rebase * Fix regression wrt correlated scanning. Correlated scan count calculations are tightly coupled with the legacy idea of a waitable code location. * Bump bd-common version 68.0.0
1 parent a3a65ae commit c30a8d4

21 files changed

Lines changed: 129 additions & 270 deletions

shared-version.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
gradle.ext.blackDuckCommonVersion='67.0.20'
1+
gradle.ext.blackDuckCommonVersion='68.0.0'
22
gradle.ext.springBootVersion='2.7.12'

src/main/java/com/blackduck/integration/detect/lifecycle/boot/product/ProductBoot.java

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ private BlackDuckRunData getBlackDuckRunData(
117117

118118
BlackDuckServicesFactory blackDuckServicesFactory = blackDuckConnectivityResult.getBlackDuckServicesFactory();
119119
setBlackDuckVersionLevel(blackDuckServicesFactory, blackDuckConnectivityResult);
120-
boolean waitAtScanLevel = shouldWaitAtScanLevel(blackDuckConnectivityResult);
121120

122121
// Fetch server detect properties settings
123122
Optional<DetectPropertiesSetting> serverDetectProperties = fetchDetectPropertiesFromServer(
@@ -126,7 +125,7 @@ private BlackDuckRunData getBlackDuckRunData(
126125
blackDuckServicesFactory.getBlackDuckApiClient()
127126
);
128127

129-
return createBlackDuckRunDataBasedOnPhoneHomeDecision(blackDuckDecision, blackDuckServicesFactory, blackDuckConnectivityResult, waitAtScanLevel, serverDetectProperties);
128+
return createBlackDuckRunDataBasedOnPhoneHomeDecision(blackDuckDecision, blackDuckServicesFactory, blackDuckConnectivityResult, serverDetectProperties);
130129
} else {
131130
if (productBootOptions.isIgnoreConnectionFailures()) {
132131
logger.info(String.format("Failed to connect to Black Duck SCA: %s", blackDuckConnectivityResult.getFailureReason()));
@@ -148,7 +147,6 @@ private BlackDuckRunData createBlackDuckRunDataBasedOnPhoneHomeDecision(
148147
BlackDuckDecision blackDuckDecision,
149148
BlackDuckServicesFactory blackDuckServicesFactory,
150149
BlackDuckConnectivityResult blackDuckConnectivityResult,
151-
boolean waitAtScanLevel,
152150
Optional<DetectPropertiesSetting> serverDetectProperties
153151
) {
154152
if (shouldUsePhoneHome(analyticsConfigurationService, blackDuckServicesFactory.getApiDiscovery(), blackDuckServicesFactory.getBlackDuckApiClient())) {
@@ -160,7 +158,6 @@ private BlackDuckRunData createBlackDuckRunDataBasedOnPhoneHomeDecision(
160158
blackDuckServicesFactory,
161159
phoneHomeManager,
162160
blackDuckConnectivityResult,
163-
waitAtScanLevel,
164161
serverDetectProperties
165162
);
166163
} catch (IntegrationException e) {
@@ -171,7 +168,7 @@ private BlackDuckRunData createBlackDuckRunDataBasedOnPhoneHomeDecision(
171168
} else {
172169
logger.debug("Skipping phone home due to Black Duck SCA global settings.");
173170
}
174-
return BlackDuckRunData.onlineNoPhoneHome(blackDuckDecision.scanMode(), blackDuckServicesFactory, blackDuckConnectivityResult, waitAtScanLevel, serverDetectProperties);
171+
return BlackDuckRunData.onlineNoPhoneHome(blackDuckDecision.scanMode(), blackDuckServicesFactory, blackDuckConnectivityResult, serverDetectProperties);
175172
}
176173

177174
private Optional<DetectPropertiesSetting> fetchDetectPropertiesFromServer(
@@ -210,18 +207,4 @@ private boolean shouldUsePhoneHome(AnalyticsConfigurationService analyticsConfig
210207
return true; // Skip phone home will be applied at the library level.
211208
}
212209
}
213-
214-
private boolean shouldWaitAtScanLevel(BlackDuckConnectivityResult blackDuckConnectivityResult) {
215-
BlackDuckVersionParser parser = new BlackDuckVersionParser();
216-
Optional<BlackDuckVersion> blackDuckServerVersion = parser.parse(blackDuckConnectivityResult.getContactedServerVersion());
217-
BlackDuckVersion minVersion = new BlackDuckVersion(2023, 1, 1);
218-
219-
boolean waitAtScanLevel = false;
220-
221-
if (blackDuckServerVersion.isPresent() && blackDuckServerVersion.get().isAtLeast(minVersion)) {
222-
waitAtScanLevel = true;
223-
}
224-
225-
return waitAtScanLevel;
226-
}
227210
}

src/main/java/com/blackduck/integration/detect/lifecycle/run/data/BlackDuckRunData.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public class BlackDuckRunData {
1616
private final BlackDuckServerConfig blackDuckServerConfig;
1717
private final BlackDuckServicesFactory blackDuckServicesFactory;
1818
private final BlackduckScanMode scanMode;
19-
private final boolean waitAtScanLevel;
2019
private final Optional<DetectPropertiesSetting> serverDetectProperties;
2120
private Optional<BlackDuckVersion> blackDuckServerVersion;
2221

@@ -25,7 +24,6 @@ private BlackDuckRunData() {
2524
this.blackDuckServerConfig = null;
2625
this.blackDuckServicesFactory = null;
2726
this.scanMode = null;
28-
this.waitAtScanLevel = false;
2927
this.serverDetectProperties = Optional.empty();
3028
this.blackDuckServerVersion = Optional.empty();
3129
}
@@ -35,16 +33,14 @@ protected BlackDuckRunData(
3533
BlackDuckConnectivityResult blackDuckConnectivityResult,
3634
BlackDuckServicesFactory blackDuckServicesFactory,
3735
BlackduckScanMode scanMode,
38-
boolean waitAtScanLevel,
3936
Optional<DetectPropertiesSetting> serverDetectProperties
4037
) {
4138
this.phoneHomeManager = phoneHomeManager;
4239
this.blackDuckServerConfig = blackDuckConnectivityResult != null ? blackDuckConnectivityResult.getBlackDuckServerConfig() : null;
4340
this.blackDuckServicesFactory = blackDuckServicesFactory;
4441
this.scanMode = scanMode;
45-
this.waitAtScanLevel = waitAtScanLevel;
46-
this.serverDetectProperties = serverDetectProperties;
4742

43+
this.serverDetectProperties = serverDetectProperties;
4844
determineBlackDuckServerVersion(blackDuckConnectivityResult);
4945
}
5046

@@ -73,20 +69,18 @@ public static BlackDuckRunData online(
7369
BlackDuckServicesFactory blackDuckServicesFactory,
7470
PhoneHomeManager phoneHomeManager,
7571
BlackDuckConnectivityResult blackDuckConnectivityResult,
76-
boolean waitAtScanLevel,
7772
Optional<DetectPropertiesSetting> serverDetectProperties
7873
) {
79-
return new BlackDuckRunData(phoneHomeManager, blackDuckConnectivityResult, blackDuckServicesFactory, scanMode, waitAtScanLevel, serverDetectProperties);
74+
return new BlackDuckRunData(phoneHomeManager, blackDuckConnectivityResult, blackDuckServicesFactory, scanMode, serverDetectProperties);
8075
}
8176

8277
public static BlackDuckRunData onlineNoPhoneHome(
8378
BlackduckScanMode scanMode,
8479
BlackDuckServicesFactory blackDuckServicesFactory,
8580
BlackDuckConnectivityResult blackDuckConnectivityResult,
86-
boolean waitAtScanLevel,
8781
Optional<DetectPropertiesSetting> serverDetectProperties
8882
) {
89-
return new BlackDuckRunData(null, blackDuckConnectivityResult, blackDuckServicesFactory, scanMode, waitAtScanLevel, serverDetectProperties);
83+
return new BlackDuckRunData(null, blackDuckConnectivityResult, blackDuckServicesFactory, scanMode, serverDetectProperties);
9084
}
9185

9286
public Boolean isNonPersistent() {
@@ -96,10 +90,6 @@ public Boolean isNonPersistent() {
9690
public BlackduckScanMode getScanMode() {
9791
return scanMode;
9892
}
99-
100-
public boolean shouldWaitAtScanLevel() {
101-
return waitAtScanLevel;
102-
}
10393

10494
public Optional<BlackDuckVersion> getBlackDuckServerVersion() {
10595
return blackDuckServerVersion;

src/main/java/com/blackduck/integration/detect/lifecycle/run/operation/OperationRunner.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ private File createProtobufHeaderFile(String type, NameVersion projectNameVersio
710710
}
711711
}
712712

713-
public void uploadBdioEntries(BlackDuckRunData blackDuckRunData, UUID bdScanId) throws IntegrationException, IOException {
713+
public void uploadBdioEntriesForRapidMode(BlackDuckRunData blackDuckRunData, UUID bdScanId) throws IntegrationException, IOException {
714714
// parse directory and upload all chunks
715715
File bdioDirectory = directoryManager.getBdioOutputDirectory();
716716

@@ -1011,7 +1011,7 @@ public void attemptToGenerateComponentLocationAnalysisIfEnabled() throws Operati
10111011
//Post actions
10121012
//End post actions
10131013

1014-
public final BdioUploadResult uploadBdioIntelligentPersistent(BlackDuckRunData blackDuckRunData, BdioResult bdioResult, Long timeout, String scassScanId) throws OperationException {
1014+
public final BdioUploadResult uploadBdioForIntelligentPersistentMode(BlackDuckRunData blackDuckRunData, BdioResult bdioResult, Long timeout, String scassScanId) throws OperationException {
10151015
return auditLog.namedPublic(
10161016
"Upload Intelligent Persistent Bdio",
10171017
() -> new IntelligentPersistentUploadOperation(
@@ -1021,8 +1021,8 @@ public final BdioUploadResult uploadBdioIntelligentPersistent(BlackDuckRunData b
10211021
);
10221022
}
10231023

1024-
public final CodeLocationWaitData calculateCodeLocationWaitData(List<WaitableCodeLocationData> codeLocationCreationDatas) throws OperationException {
1025-
return auditLog.namedInternal("Calculate Code Location Wait Data", () -> new CodeLocationWaitCalculator().calculateWaitData(codeLocationCreationDatas));
1024+
public final CodeLocationWaitData calculateCodeLocationWaitDataGivenNotificationRangeStart(List<WaitableCodeLocationData> codeLocationCreationDatas, long codeLocationsUploadStartTime) throws OperationException {
1025+
return auditLog.namedInternal("Calculate Code Location Wait Data", () -> new CodeLocationWaitCalculator().calculateWaitData(codeLocationCreationDatas, codeLocationsUploadStartTime));
10261026
}
10271027

10281028
public final void publishCodeLocationData(Set<FormattedCodeLocation> codeLocationData) throws OperationException {
@@ -1297,13 +1297,6 @@ public ScanBatchRunner createScanBatchRunnerFromLocalInstall(File installDirecto
12971297
});
12981298
}
12991299

1300-
public NotificationTaskRange createCodeLocationRange(BlackDuckRunData blackDuckRunData) throws OperationException {
1301-
return auditLog.namedInternal(
1302-
"Create Code Location Task Range",
1303-
() -> blackDuckRunData.getBlackDuckServicesFactory().createCodeLocationCreationService().calculateCodeLocationRange()
1304-
);
1305-
}
1306-
13071300
public SignatureScanOuputResult signatureScan(ScanBatch scanBatch, ScanBatchRunner scanBatchRunner) throws OperationException {
13081301
return auditLog.namedPublic("Execute Signature Scan CLI", "SigScan", () -> new SignatureScanOperation().performScanActions(scanBatch, scanBatchRunner));
13091302
}
@@ -1321,13 +1314,12 @@ public void publishSignatureScanReport(List<SignatureScannerReport> report) thro
13211314
}
13221315

13231316
public SignatureScannerCodeLocationResult calculateWaitableSignatureScannerCodeLocations(
1324-
NotificationTaskRange notificationTaskRange,
13251317
List<SignatureScannerReport> reports
13261318
) throws OperationException {
13271319
return auditLog.namedInternal(
13281320
"Calculate Signature Scanner Waitable Code Locations",
13291321
() -> new CalculateWaitableSignatureScanCodeLocations()
1330-
.calculateWaitableCodeLocations(notificationTaskRange, reports)
1322+
.calculateWaitableCodeLocations(reports)
13311323
);
13321324
}
13331325

src/main/java/com/blackduck/integration/detect/lifecycle/run/step/IacScanStepRunner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private IacScanReport performOnlineScan(
9696
try {
9797
File resultsFile = operationRunner.performIacScanScan(scanTarget, iacScanExe, count);
9898
String codeLocationName = operationRunner.createIacScanCodeLocationName(scanTarget, projectNameVersion);
99-
String scanId = initiateScan(detectRunUuid, projectNameVersion, blackDuckRunData.getBlackDuckServicesFactory().createBdio2FileUploadService(), codeLocationName
99+
String scanId = initiateIacScan(detectRunUuid, projectNameVersion, blackDuckRunData.getBlackDuckServicesFactory().createBdio2FileUploadService(), codeLocationName
100100
);
101101
operationRunner.uploadIacScanResults(blackDuckRunData, resultsFile, scanId);
102102
return IacScanReport.SUCCESS_ONLINE(scanTarget, codeLocationName);
@@ -121,7 +121,7 @@ public IacScanReport performOfflineScan(File scanTarget, File iacScanExe, int co
121121
//TODO- look into extracting scan initiation to another class
122122

123123
//TODO- this should only be necessary if we didn't already upload BDIO during DETECTORS phase
124-
private String initiateScan(
124+
private String initiateIacScan(
125125
String detectRunUuid,
126126
NameVersion projectNameVersion, Bdio2FileUploadService bdio2FileUploadService, String codeLocationNameOverride
127127
)

0 commit comments

Comments
 (0)