-
Notifications
You must be signed in to change notification settings - Fork 639
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pipeline): add a pipelineNameFilter query param to the /pipeline…
…s/{application} endpoint (#1504) * feat(pipelineController): add a pipelineNameFilter query param to the /pipelines/{application} endpoint This adds a pipelineNameFilter query parameter to the /pipelines/{application} endpoint. If pipelineNameFilter is present, the endpoint will return a list of pipelines whose pipeline name contains the pipelineNameFilter. This change is necessary to enable some optimizations in the front end - namely, filtering pipelines on the backend, instead of always querying for every pipeline in an application, and filtering the list in the front end. * feat(pipeline): check for null pipeline name and log error * fix(test/pipeline): updating tests and fixing getPipelinesByApplication implementation. * fix(pipeline): make the comparison case insensitive. * refactor(tests): convert groovy tests to java * fix(tests): address minor issues --------- Co-authored-by: Richard Timpson <[email protected]>
- Loading branch information
1 parent
e5f323d
commit 51f2d15
Showing
11 changed files
with
323 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
...t50-core/src/test/java/com/netflix/spinnaker/front50/pipeline/DefaultPipelineDAOTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Copyright 2023 Salesforce, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.netflix.spinnaker.front50.pipeline; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.ArgumentMatchers.anyBoolean; | ||
import static org.mockito.Mockito.doReturn; | ||
|
||
import com.netflix.spinnaker.front50.api.model.pipeline.Pipeline; | ||
import com.netflix.spinnaker.front50.model.pipeline.DefaultPipelineDAO; | ||
import com.netflix.spinnaker.kork.sql.test.SqlTestUtil; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
import org.mockito.Mockito; | ||
|
||
public abstract class DefaultPipelineDAOTest extends PipelineDAOSpec<DefaultPipelineDAO> { | ||
|
||
protected DefaultPipelineDAO pipelineDAO; | ||
|
||
@Override | ||
public DefaultPipelineDAO getInstance() { | ||
return getDefaultPipelineDAO(); | ||
} | ||
|
||
public abstract DefaultPipelineDAO getDefaultPipelineDAO(); | ||
|
||
@BeforeEach | ||
public void setup() { | ||
this.pipelineDAO = Mockito.spy(getDefaultPipelineDAO()); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"'app', 'pipelineNameA', 'NameA', 'pipelineNameA'", | ||
"'app', 'pipelineNameA', , 'pipelineNameA'", | ||
"'app', , , " | ||
}) | ||
public void shouldReturnCorrectPipelinesWhenRequestingPipelinesByApplicationWithNameFilter( | ||
String applicationName, | ||
String pipelineName, | ||
String pipelineNameFilter, | ||
String expectedPipelineName) { | ||
|
||
Pipeline pipeline = new Pipeline(); | ||
pipeline.setId("0"); | ||
pipeline.setApplication(applicationName); | ||
pipeline.setName(pipelineName); | ||
|
||
doReturn(List.of(pipeline)).when(pipelineDAO).all(anyBoolean()); | ||
|
||
Collection<Pipeline> pipelines = | ||
pipelineDAO.getPipelinesByApplication("app", pipelineNameFilter, true); | ||
|
||
Pipeline resultPipeline = pipelines.iterator().next(); | ||
assertEquals(resultPipeline.getName(), expectedPipelineName); | ||
assertEquals(resultPipeline.getApplication(), "app"); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"'app', , 'NameA'", | ||
"'bad', 'pipelineNameA', 'NameA'", | ||
"'bad', , 'NameA'", | ||
"'bad', 'pipelineNameA', ", | ||
"'bad', , " | ||
}) | ||
public void shouldReturnNoPipelinesWhenRequestingPipelinesByApplicationWithNameFilter( | ||
String applicationName, String pipelineName, String pipelineNameFilter) { | ||
|
||
Pipeline pipeline = new Pipeline(); | ||
pipeline.setId("0"); | ||
pipeline.setApplication(applicationName); | ||
pipeline.setName(pipelineName); | ||
|
||
doReturn(List.of(pipeline)).when(pipelineDAO).all(true); | ||
|
||
Collection<Pipeline> pipelines = | ||
pipelineDAO.getPipelinesByApplication("app", pipelineNameFilter, true); | ||
|
||
assertEquals(0, pipelines.size()); | ||
} | ||
} | ||
|
||
class SqlDefaultPipelineDAOTest extends DefaultPipelineDAOTest { | ||
|
||
private SqlTestUtil.TestDatabase database = SqlTestUtil.initTcMysqlDatabase(); | ||
|
||
@AfterEach | ||
public void cleanup() { | ||
if (database != null) { | ||
SqlTestUtil.cleanupDb(database.context); | ||
database.close(); | ||
} | ||
} | ||
|
||
@Override | ||
public DefaultPipelineDAO getDefaultPipelineDAO() { | ||
return SqlPipelineDAOTestConfiguration.createPipelineDAO(database); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...src/main/java/com/netflix/spinnaker/front50/pipeline/SqlPipelineDAOTestConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2023 Salesforce, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.netflix.spinnaker.front50.pipeline; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.netflix.spectator.api.NoopRegistry; | ||
import com.netflix.spinnaker.config.Front50SqlProperties; | ||
import com.netflix.spinnaker.front50.config.StorageServiceConfigurationProperties; | ||
import com.netflix.spinnaker.front50.model.DefaultObjectKeyLoader; | ||
import com.netflix.spinnaker.front50.model.SqlStorageService; | ||
import com.netflix.spinnaker.front50.model.pipeline.DefaultPipelineDAO; | ||
import com.netflix.spinnaker.kork.sql.config.SqlRetryProperties; | ||
import com.netflix.spinnaker.kork.sql.test.SqlTestUtil; | ||
import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; | ||
import java.time.Clock; | ||
import java.util.concurrent.Executors; | ||
import rx.Scheduler; | ||
import rx.schedulers.Schedulers; | ||
|
||
public class SqlPipelineDAOTestConfiguration { | ||
|
||
public static DefaultPipelineDAO createPipelineDAO(SqlTestUtil.TestDatabase database) { | ||
Scheduler scheduler = Schedulers.from(Executors.newFixedThreadPool(1)); | ||
|
||
StorageServiceConfigurationProperties.PerObjectType pipelineDAOConfigProperties = | ||
new StorageServiceConfigurationProperties().getPipeline(); | ||
|
||
SqlStorageService storageService = | ||
new SqlStorageService( | ||
new ObjectMapper(), | ||
new NoopRegistry(), | ||
database.context, | ||
Clock.systemDefaultZone(), | ||
new SqlRetryProperties(), | ||
1, | ||
"default", | ||
new Front50SqlProperties()); | ||
|
||
// Configure PipelineDAO properties | ||
pipelineDAOConfigProperties.setRefreshMs(0); | ||
pipelineDAOConfigProperties.setShouldWarmCache(false); | ||
|
||
DefaultPipelineDAO pipelineDAO = | ||
new DefaultPipelineDAO( | ||
storageService, | ||
scheduler, | ||
new DefaultObjectKeyLoader(storageService), | ||
pipelineDAOConfigProperties, | ||
new NoopRegistry(), | ||
CircuitBreakerRegistry.ofDefaults()); | ||
|
||
// refreshing to initialize the cache with an empty set | ||
pipelineDAO.all(true); | ||
|
||
return pipelineDAO; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.