-
Notifications
You must be signed in to change notification settings - Fork 0
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
Added auto book feature #2
Merged
+236
−38
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
43e6808
Added auto book feature
Nikita-Smirnov-Exactpro e34f998
corrected after review
Nikita-Smirnov-Exactpro 28f7157
Update cradle-admin-tool-http/src/main/java/com/exactpro/th2/cradle/a…
Nikita-Smirnov-Exactpro eac5645
corrected after review
Nikita-Smirnov-Exactpro 90a9a6d
corrected after review
Nikita-Smirnov-Exactpro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
51 changes: 51 additions & 0 deletions
51
...admin-tool-http/src/main/java/com/exactpro/th2/cradle/adm/http/AutoBookConfiguration.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,51 @@ | ||
/* | ||
* Copyright 2023 Exactpro (Exactpro Systems Limited) | ||
* | ||
* 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.exactpro.th2.cradle.adm.http; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import java.time.Instant; | ||
|
||
@SuppressWarnings("FieldMayBeFinal") | ||
public class AutoBookConfiguration { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use |
||
@JsonProperty("book-full-name") | ||
private String bookFullName = null; | ||
@JsonProperty("book-description") | ||
private String bookDescription = null; | ||
@JsonProperty("book-creation-time") | ||
private Instant bookCreationTime = null; | ||
|
||
public String getBookFullName() { | ||
return bookFullName; | ||
} | ||
|
||
public String getBookDescription() { | ||
return bookDescription; | ||
} | ||
|
||
public Instant getBookCreationTime() { | ||
return bookCreationTime; | ||
} | ||
|
||
Nikita-Smirnov-Exactpro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Override | ||
public String toString() { | ||
return "AutoBookConfiguration{" + | ||
"bookFullName='" + bookFullName + '\'' + | ||
", bookDescription='" + bookDescription + '\'' + | ||
", bookCreationTime=" + bookCreationTime + | ||
'}'; | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
cradle-admin-tool-http/src/main/java/com/exactpro/th2/cradle/adm/http/AutoBookUtils.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,91 @@ | ||
/* | ||
* Copyright 2023 Exactpro (Exactpro Systems Limited) | ||
* | ||
* 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.exactpro.th2.cradle.adm.http; | ||
|
||
import com.exactpro.cradle.BookId; | ||
import com.exactpro.cradle.BookInfo; | ||
import com.exactpro.cradle.BookToAdd; | ||
import com.exactpro.cradle.CradleStorage; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.time.Instant; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static org.apache.commons.lang3.StringUtils.defaultIfBlank; | ||
import static org.apache.commons.lang3.StringUtils.lowerCase; | ||
import static org.apache.commons.lang3.StringUtils.trim; | ||
|
||
public class AutoBookUtils { | ||
Nikita-Smirnov-Exactpro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(AutoBookUtils.class); | ||
public static final String AUTO_BOOK_DESCRIPTION = "auto-book"; | ||
|
||
public static void createBooks(@NotNull CradleStorage storage, @Nullable Map<String, AutoBookConfiguration> autoBooks) { | ||
requireNonNull(storage, "Cradle storage can't be null"); | ||
|
||
if (autoBooks == null || autoBooks.isEmpty()) { | ||
LOGGER.info("Auto book configuration is empty"); | ||
return; | ||
} | ||
|
||
Set<String> existedBooks = storage.getBooks().stream() | ||
.map(BookInfo::getId) | ||
.map(BookId::getName) | ||
.collect(Collectors.toSet()); | ||
|
||
autoBooks.forEach((bookName, config) -> { | ||
try { | ||
bookName = lowerCase(trim(bookName)); | ||
if (bookName == null || bookName.isEmpty()) { | ||
LOGGER.warn("book with null or empty name can't be created"); | ||
Nikita-Smirnov-Exactpro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if (existedBooks.contains(bookName)) { | ||
return; | ||
} | ||
|
||
BookToAdd bookToAdd; | ||
if (config == null) { | ||
bookToAdd = new BookToAdd(bookName); | ||
bookToAdd.setFullName(bookName); | ||
bookToAdd.setDesc(AUTO_BOOK_DESCRIPTION); | ||
} else { | ||
bookToAdd = new BookToAdd( | ||
bookName, | ||
config.getBookCreationTime() != null ? config.getBookCreationTime() : Instant.now() | ||
); | ||
bookToAdd.setFullName(trim(defaultIfBlank(config.getBookFullName(), bookName))); | ||
bookToAdd.setDesc(trim(defaultIfBlank(config.getBookDescription(), AUTO_BOOK_DESCRIPTION))); | ||
} | ||
|
||
storage.addBook(bookToAdd); | ||
|
||
LOGGER.info("Created '{}' book, time: {}, full name: {}, description: {}", | ||
bookName, | ||
bookToAdd.getCreated(), | ||
bookToAdd.getFullName(), | ||
bookToAdd.getDesc()); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Book with name '" + bookName + "' and config " + config + " can't be created", e); | ||
} | ||
}); | ||
} | ||
} |
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
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 +1 @@ | ||
release_version = 1.7.2 | ||
release_version = 1.8.0 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that we don't need to provide the ability to specify the exact time for a book. This is
auto
functionality. So, I think it just should create a book with the current time (if the book does not exist).A user always can call the endpoint to create a book with the time he or she needs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, it sound like correct but I think admin-tool should create book with time now - 1 hour and create a first page with the same date because schema can contain other active conns which can be started before admin-tool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then maybe this is the problem in the schema. The cradle admin should be deployed before other components. Also, you always can create a book in the past using REST API in case there are events/messages from components that were deployed before cradle-admin...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then maybe this is the problem in the schema.
I don't think so, because by the th2 concept order of component starting doesn't matter.REST API is complicated way when you need the simplest book to start work.
I try to solve
start on a virgin machine
problem by this change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, because by the th2 concept order of component starting doesn't matter.
We have a problem then because the order does matter)) What if the cradle-admin will be started after 1 hour + 1 second after the first component produces event/message? We still will have the problem that there is no book that matches the event/message time.
We don't make our and users' lives easier by saying
let's just substruct an hour
orplease, set the exact time you need for the book in config
. The only solution to the problem is to start cradle-admin before other components. Otherwise, we are doomed to face that potential problem again and again.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your statement is true when CR cradle-admin doesn't exist at the start environment moment or it has critical problem in configuration and user doesn't check environment.
In fact, user can have a problem event infra will start cradle-admin at first. We can solve part of problems when infra will find all book mentioned in schema and doesn't create estore / mstore queue until books have been created