Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring boot autoconfigure #3

Draft
wants to merge 14 commits into
base: springBootAutoconfigure
Choose a base branch
from

Conversation

MusaTalluzi
Copy link

@MusaTalluzi MusaTalluzi commented Nov 23, 2019

Major changes:

  • Add JPA annotations to persist Timeslot, Room and Lesson entitites with id auto generated.
  • On each problem fact change (add Lesson, add Room, add Timeslot) restart solving (N.B. since autoRefreshCount is set to 16, updates after problem fact changes might not refresh if it occurs after 16 refreshes)

You can view the database console at localhost:8080/h2-console and setting the required fields as in resources/application.properties

import org.springframework.stereotype.Service;

@Service
public class RoomService {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In spring, we can avoid having to crate these services by exposing the RoomRepository directly as a REST service.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less code is better, as the aim is to build this example from scratch during presentations. If we can reuse the spring approach to just expose the RoomRepository, LessonRepository and TimeslotRepository as REST services automatically (which have pagination btw), which having to add additional classes, that would make a big difference.

spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe if we simply add h2 to the classpath, we don't need these properties at all. especially hiberante 5.3+ autodetects the driverClasName and dialect IIRC.

<dependency><!-- TODO move this into kie-parent -->
<groupId>org.springframework.boot</groupId>
<version>${version.org.springframework.boot}</version>
<artifactId>spring-boot-devtools</artifactId>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version after artifactId

@@ -27,11 +27,11 @@
<groupId>org.optaplanner</groupId>
<artifactId>optaplanner-core</artifactId>
</dependency>
<!-- External dependencies -->
<dependency>
<groupId>org.optaplanner</groupId>
<artifactId>optaplanner-spring-boot-starter</artifactId>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an internal dependency, because the groupId is org.optaplanner


@NotNull
private DayOfWeek dayOfWeek;
@NotNull
@JsonFormat(pattern = "hh:mm")
Copy link
Owner

@ge0ffrey ge0ffrey Nov 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume these needed to be removed to get the saving of new timeslots to work?
(That's ok, just want to understand.)

lesson.getSubject(), lesson.getTeacher(), lesson.getStudentGroup()));
return timeTable;
});
timetableService.addLesson(lesson);
Copy link
Owner

@ge0ffrey ge0ffrey Nov 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these CRUD methods on this contoller can dissappear if the RoomRepository etc are exposed as rest services.
The only thing that would remain is to get a timetable (which includes the score btw) and solving and terminateEarly of the current timetable.

timeTableReference = new AtomicReference<>(generateProblem());
}

private TimeTable generateProblem() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this into a Spring boot Runner? So it runs upon bootstrap (not when the first REST method is called)

import org.springframework.web.bind.annotation.RequestBody;

@Service
public class TimetableService {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to TimeTableService (the T of Table is capital)
TimeTableService and TimeTableController are duplicates in this simple example (not in in-depth architectures), there can only be one.

ge0ffrey pushed a commit that referenced this pull request Feb 4, 2021
* Initial test version update

* # This is a combination of 11 commits.
# This is the 1st commit message:

Remove quite mode on grep check
Enclose to ""
Stage build.gradle as well

# This is the commit message #2:

Add build phase to test updated versions

# The commit message #3 will be skipped:

# Cleanup testing code

# The commit message #4 will be skipped:

# Add removed stages

# This is the commit message apache#5:

Update Jenkinsfile.deploy

Co-authored-by: Radovan Synek <rsynek@redhat.com>
# This is the commit message apache#6:

Remove removeJbossNexusFromMavenAndGradle
Since we need to remove Nexus only in stable will use it only for stable branch after hard reset in a separate commit

# The commit message apache#7 will be skipped:

# Stage pom and gradle files in one commit
#
# Co-authored-by: Radovan Synek <rsynek@redhat.com>

# The commit message apache#8 will be skipped:

# Create PR for release branch
#
# Create PR with changed versions in pom.xml and build.gradle
#
# Clean up removeJbossNexusFromMavenAndGradle

# The commit message apache#9 will be skipped:

# Remove unnecessary commit
#
# Careful with commitments in a range. If files have not been changed and you add it and commit then git will return exit code 1 no files matched

# The commit message apache#10 will be skipped:

# Test Create PRs without VRP blocker

# The commit message apache#11 will be skipped:

# Add build branch property for quickstarts
#
# In case if it is release - base branch will be gathered from build branch. It is getting generated automatically from kogito pipelines.
#
# Cases for different base usages:
# {release, nightly, custom}
# And they related branches that would be used
# {release branch, development, params.QUICKSTARTS_BUILD_BRANCH_NAME}

* Remove quite mode on grep check
Enclose to ""
Stage build.gradle as well

Add build phase to test updated versions

Update Jenkinsfile.deploy

Co-authored-by: Radovan Synek <rsynek@redhat.com>

Remove removeJbossNexusFromMavenAndGradle
Since we need to remove Nexus only in stable will use it only for stable branch after hard reset in a separate commit

Update and reset stable branch

Despite other repo quickstarts need to be reset to stable from release branch

Additionally it should not contain JBoss nexus

So I create a branch from release and change pom and gradle files to not contain nexus repo, then I use forcePush function from kiegroup/jenkins-pipeline-shared-libraries#131

Add promotion of the protection properties

Return false if dismiss_stale_reviews or require_code_owner_reviews is null

* Assert protection does not changed for other then force push properties

Added check that other then allow force push protection properties stays the same after protection update
Reorganized code to fit in one screen
Removed allowEmptyResults flag from sh calls

* Apply suggestions from code review

Spacing and stage rename

Co-authored-by: Radovan Synek <rsynek@redhat.com>

* Add assertGithubCLI function

Checks if gh utility to send authorized requests is available in ghPath

* Add fail fast messages

If put request will fail to update allow force push then it will fail on assert after the command will be executed
In case if there was some unexpected difference in protection then the message would be:
```
ERROR: Protection settings lost
Before:
{
  "url": "https://api.github.com/repos/dupliaka/optaplanner-quickstarts/branches/stable/protection",
  "required_pull_request_reviews": {
    "url": "https://api.github.com/repos/dupliaka/optaplanner-quickstarts/branches/stable/protection/required_pull_request_reviews",
    "dismiss_stale_reviews": false,
    "require_code_owner_reviews": false
  },
  "enforce_admins": {
    "url": "https://api.github.com/repos/dupliaka/optaplanner-quickstarts/branches/stable/protection/enforce_admins",
    "enabled": false
  },
  "required_linear_history": {
    "enabled": false
  },
  "allow_deletions": {
    "enabled": false
  }
}

After:
{
  "url": "https://api.github.com/repos/dupliaka/optaplanner-quickstarts/branches/stable/protection",
  "required_pull_request_reviews": {
    "url": "https://api.github.com/repos/dupliaka/optaplanner-quickstarts/branches/stable/protection/required_pull_request_reviews",
    "dismiss_stale_reviews": false,
    "require_code_owner_reviews": false
  },
  "enforce_admins": {
    "url": "https://api.github.com/repos/dupliaka/optaplanner-quickstarts/branches/stable/protection/enforce_admins",
    "enabled": false
  },
  "required_linear_history": {
    "enabled": false
  },
  "allow_force_pushes": {
    "enabled": true
  },
  "allow_deletions": {
    "enabled": false
  }
}

Differences:
14a15,17
>   "allow_force_pushes": {
>     "enabled": true
>   },

Protection parameters:
{
  "required_status_checks": null,
  "required_pull_request_reviews": {
    "dismiss_stale_reviews": false,
    "require_code_owner_reviews": false
  },
  "enforce_admins": false,
  "restrictions": null,
  "allow_force_pushes": true
}
 Please rollback to Before state and update getProtectionMapScript
 ```

Co-authored-by: adupliak <adupliaka@gmail.com>
Co-authored-by: Radovan Synek <rsynek@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants