-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
183 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.flowci.build.business; | ||
|
||
import com.flowci.build.model.Build; | ||
import com.flowci.common.model.Variables; | ||
|
||
public interface CreateBuild { | ||
Build invoke(Long flowId, Build.Trigger trigger, Variables inputs); | ||
} |
16 changes: 0 additions & 16 deletions
16
src/main/java/com/flowci/build/business/CreateNewBuild.java
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
src/main/java/com/flowci/build/business/FetchYamlFromGit.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,7 @@ | ||
package com.flowci.build.business; | ||
|
||
import com.flowci.build.model.Build; | ||
|
||
public interface FetchYamlFromGit { | ||
void invoke(Build build); | ||
} |
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,5 @@ | ||
package com.flowci.build.business; | ||
|
||
public interface WaitForAgent { | ||
void invoke(Long buildId); | ||
} |
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
13 changes: 13 additions & 0 deletions
13
src/main/java/com/flowci/build/business/impl/FetchYamlFromGitImpl.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,13 @@ | ||
package com.flowci.build.business.impl; | ||
|
||
import com.flowci.build.business.FetchYamlFromGit; | ||
import com.flowci.build.model.Build; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class FetchYamlFromGitImpl implements FetchYamlFromGit { | ||
@Override | ||
public void invoke(Build build) { | ||
// TODO: | ||
} | ||
} |
18 changes: 9 additions & 9 deletions
18
src/main/java/com/flowci/build/business/impl/TriggerBuildImpl.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 |
---|---|---|
@@ -1,26 +1,26 @@ | ||
package com.flowci.build.business.impl; | ||
|
||
import com.flowci.build.business.CreateNewBuild; | ||
import com.flowci.build.business.CreateBuild; | ||
import com.flowci.build.business.TriggerBuild; | ||
import com.flowci.build.business.WaitForAgent; | ||
import com.flowci.build.model.Build; | ||
import com.flowci.common.model.Variables; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Slf4j | ||
@Component | ||
@AllArgsConstructor | ||
public class TriggerBuildImpl implements TriggerBuild { | ||
|
||
private final CreateNewBuild createNewBuild; | ||
private final CreateBuild createBuild; | ||
private final WaitForAgent waitForAgent; | ||
|
||
@Override | ||
@Transactional | ||
public Build invoke(Long flowId, Build.Trigger trigger, Variables inputs) { | ||
var build = createNewBuild.invoke(flowId, trigger, inputs); | ||
|
||
// put to queue, and wait | ||
|
||
return null; | ||
var build = createBuild.invoke(flowId, trigger, inputs); | ||
waitForAgent.invoke(build.getId()); | ||
return build; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/flowci/build/business/impl/WaitForAgentImpl.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,19 @@ | ||
package com.flowci.build.business.impl; | ||
|
||
import com.flowci.build.business.WaitForAgent; | ||
import com.flowci.build.model.Build; | ||
import com.flowci.build.repo.BuildRepo; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@AllArgsConstructor | ||
public class WaitForAgentImpl implements WaitForAgent { | ||
|
||
private final BuildRepo buildRepo; | ||
|
||
@Override | ||
public void invoke(Long buildId) { | ||
buildRepo.updateBuildStatusById(buildId, Build.Status.QUEUED); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.flowci.build.model; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class GitRef { | ||
|
||
private String commitHash; | ||
} |
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
74 changes: 74 additions & 0 deletions
74
src/test/java/com/flowci/build/business/CreateBuildTest.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,74 @@ | ||
package com.flowci.build.business; | ||
|
||
import com.flowci.SpringTest; | ||
import com.flowci.build.model.Build; | ||
import com.flowci.build.model.BuildYaml; | ||
import com.flowci.common.model.Variables; | ||
import com.flowci.flow.business.FetchFlow; | ||
import com.flowci.flow.business.FetchFlowYamlContent; | ||
import com.flowci.flow.model.Flow; | ||
import com.flowci.flow.model.FlowYaml; | ||
import com.flowci.yaml.business.ParseYamlV2; | ||
import com.flowci.yaml.model.FlowV2; | ||
import org.instancio.Instancio; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.ArgumentCaptor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
|
||
import static com.flowci.TestUtils.newDummyInstance; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.ArgumentMatchers.anyLong; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.when; | ||
|
||
class CreateBuildTest extends SpringTest { | ||
|
||
@MockBean | ||
private FetchFlow fetchFlow; | ||
|
||
@MockBean | ||
private FetchFlowYamlContent fetchFlowYamlContent; | ||
|
||
@MockBean | ||
private ParseYamlV2 parseYamlV2; | ||
|
||
@Autowired | ||
private MockRepositoriesConfig mockRepositoriesConfig; | ||
|
||
@Autowired | ||
private CreateBuild createBuild; | ||
|
||
@Test | ||
void givenFlow_whenCreating_thenBuildIsCreated() { | ||
var mockFlow = newDummyInstance(Flow.class).create(); | ||
when(fetchFlow.invoke(anyLong())).thenReturn(mockFlow); | ||
var mockFlowYaml = newDummyInstance(FlowYaml.class).create(); | ||
when(fetchFlowYamlContent.invoke(anyLong())).thenReturn(mockFlowYaml.getYaml()); | ||
when(parseYamlV2.invoke(anyString())).thenReturn(Instancio.of(FlowV2.class).create()); | ||
|
||
var mockBuildRepo = mockRepositoriesConfig.getBuildRepo(); | ||
var buildCaptor = ArgumentCaptor.forClass(Build.class); | ||
when(mockBuildRepo.save(buildCaptor.capture())) | ||
.thenAnswer(opt -> opt.getArgument(0)); | ||
|
||
var mockBuildYamlRepo = mockRepositoriesConfig.getBuildYamlRepo(); | ||
var buildYamlCaptor = ArgumentCaptor.forClass(BuildYaml.class); | ||
when(mockBuildYamlRepo.save(buildYamlCaptor.capture())) | ||
.thenAnswer(opt -> opt.getArgument(0)); | ||
|
||
var inputs = new Variables(); | ||
inputs.put("v1", "hello"); | ||
inputs.put("v2", "world"); | ||
createBuild.invoke(1L, Build.Trigger.API, inputs); | ||
|
||
var build = buildCaptor.getValue(); | ||
assertEquals(mockFlow.getId(), build.getFlowId()); | ||
assertEquals(Build.Trigger.API, build.getTrigger()); | ||
|
||
var buildYaml = buildYamlCaptor.getValue(); | ||
assertEquals("hello", buildYaml.getVariables().get("v1")); | ||
assertEquals("world", buildYaml.getVariables().get("v2")); | ||
assertEquals(mockFlowYaml.getYaml(), buildYaml.getYaml()); | ||
} | ||
} |
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