Skip to content

[NAE-1909] Elasticsearch index per URI node #218

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

Open
wants to merge 26 commits into
base: release/6.4.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
740b137
[NAE-1909] Elasticsearch index per URI node
machacjozef Jul 29, 2023
f9dad9a
[NAE-1909] Elasticsearch index per URI node
machacjozef Jul 31, 2023
65d9220
[NAE-1909] Elasticsearch index per URI node
machacjozef Aug 1, 2023
cecc385
[NAE-1909] Elasticsearch index per URI node
machacjozef Aug 1, 2023
65ddc59
[NAE-1909] Elasticsearch index per URI node
machacjozef Aug 2, 2023
bdffbc3
[NAE-1909] Elasticsearch index per URI node
machacjozef Aug 2, 2023
2e50602
[NAE-1909] Elasticsearch index per URI node
machacjozef Aug 3, 2023
d241664
[NAE-1909] Elasticsearch index per URI node
machacjozef Aug 3, 2023
1debb69
[NAE-1909] Elasticsearch index per URI node
machacjozef Aug 3, 2023
fba805d
[NAE-1909] Elasticsearch index per URI node
machacjozef Aug 3, 2023
12bf21d
[NAE-1909] Elasticsearch index per URI node
machacjozef Aug 3, 2023
5b05384
[NAE-1909] Elasticsearch index per URI node
machacjozef Aug 3, 2023
383ad2c
[NAE-1909] Elasticsearch index per URI node
machacjozef Aug 3, 2023
e85e15b
[NAE-1909] Elasticsearch index per URI node
machacjozef Aug 3, 2023
003fc83
[NAE-1909] Elasticsearch index per URI node
machacjozef Aug 3, 2023
72c8eed
[NAE-1909] Elasticsearch index per URI node
machacjozef Aug 3, 2023
9d1b0cd
[NAE-1909] Elasticsearch index per URI node
machacjozef Aug 7, 2023
350990f
[NAE-1909] Elasticsearch index per URI node
machacjozef Aug 8, 2023
96bb5bc
[NAE-1909] Elasticsearch index per URI node
machacjozef Aug 8, 2023
2e1d1ab
Merge remote-tracking branch 'origin/release/6.4.0' into NAE-1909
machacjozef Mar 7, 2024
e71089a
[NAE-1909] Elasticsearch index per URI node
machacjozef Mar 19, 2024
c908b21
Merge remote-tracking branch 'origin/release/6.4.0' into NAE-1909
machacjozef Mar 19, 2024
ef9b76f
[NAE-1909] Elasticsearch index per URI node
machacjozef Mar 19, 2024
8bb605b
[NAE-1909] Elasticsearch index per URI node
machacjozef Mar 19, 2024
a6e78a1
[NAE-1909] Elasticsearch index per URI node
machacjozef Apr 8, 2024
3e3bcd1
[NAE-1909] Elasticsearch index per URI node
machacjozef Apr 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Full Changelog: [https://github.com/netgrif/application-engine/commits/v6.3.2](h
- [NAE-1908] NAE-1906 Improvements
- [NAE-1937] Fix the problem with empty string in filter
- [NAE-1884] Improve execution of auto trigger tasks
- [NAE-1942] Authorization Bypass Process Download

### Added
- [NAE-1901] Taskref list rendering update
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.netgrif.application.engine.startup

import com.netgrif.application.engine.configuration.ElasticsearchConfiguration
import com.netgrif.application.engine.configuration.properties.UriProperties
import com.netgrif.application.engine.elastic.domain.ElasticCase
import com.netgrif.application.engine.elastic.domain.ElasticPetriNet
Expand Down Expand Up @@ -42,20 +43,41 @@ class ElasticsearchRunner extends AbstractOrderedCommandLineRunner {
@Autowired
private IElasticIndexService template

@Autowired
private ElasticsearchConfiguration properties

@Override
void run(String... args) throws Exception {
if (drop) {
log.info("Dropping Elasticsearch database [${url}:${port}/${clusterName}]")
template.deleteIndex(ElasticPetriNet.class)
template.deleteIndex(ElasticCase.class)
template.deleteIndex(ElasticTask.class)
}
if (!template.indexExists(petriNetIndex)) {
log.info "Creating Elasticsearch case index [${petriNetIndex}]"
template.createIndex(ElasticPetriNet.class)
} else {
log.info "Elasticsearch case index exists [${caseIndex}]"
log.info("Dropping Elasticsearch database [${url}:${port}/${clusterName}]");
if (template.indexExists(caseIndex)) {
template.deleteIndex(ElasticCase.class)
}
if (template.indexExists(taskIndex)) {
template.deleteIndex(ElasticTask.class)
}
if (!template.indexExists(petriNetIndex)) {
log.info "Creating Elasticsearch case index [${petriNetIndex}]"
template.createIndex(ElasticPetriNet.class)
}
try {
template.getAllDynamicIndexes().forEach(indexName -> {
if (template.indexExists(indexName)) {
log.info("Deleting dynamic index {}", indexName);
template.deleteIndex(indexName);
} else {
log.warn("Index {} does not exist, skipping deletion.", indexName);
}
})
} catch (Exception e){
log.warn("Index {} does not exist, skipping deletion.", e.message);
}
if (template.indexExists(uriProperties.index)) {
template.deleteIndex(UriNode.class)
}
template.evictAllCaches();
}

if (!template.indexExists(caseIndex)) {
log.info "Creating Elasticsearch case index [${caseIndex}]"
template.createIndex(ElasticCase.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Aspect
@EnableCaching
@EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL)
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableAspectJAutoProxy
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
@EnableMongoAuditing
@Aspect
@Slf4j
@EnableAspectJAutoProxy
@EnableGlobalMethodSecurity(prePostEnabled = true)
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL)
public class ApplicationEngine {

@Around("execution(* com.netgrif.application.engine.startup.AbstractOrderedCommandLineRunner+.run(..))")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import com.netgrif.application.engine.elastic.domain.ElasticCaseRepository;
import com.netgrif.application.engine.elastic.domain.ElasticTaskRepository;
import com.netgrif.application.engine.elastic.service.ElasticCaseService;
import com.netgrif.application.engine.elastic.service.ElasticIndexService;
import com.netgrif.application.engine.elastic.service.ElasticTaskService;
import com.netgrif.application.engine.elastic.service.executors.Executor;
import com.netgrif.application.engine.elastic.service.interfaces.IElasticCaseService;
import com.netgrif.application.engine.elastic.service.interfaces.IElasticIndexService;
import com.netgrif.application.engine.elastic.service.interfaces.IElasticTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand All @@ -23,9 +25,6 @@
)
public class ElasticServiceConfiguration {

@Autowired
private ElasticCaseRepository caseRepository;

@Autowired
private ElasticTaskRepository taskRepository;

Expand Down Expand Up @@ -54,18 +53,22 @@ public Executor reindexingTaskTaskExecutor() {
@Bean
@Primary
public IElasticCaseService elasticCaseService() {
return new ElasticCaseService(caseRepository, elasticsearchTemplate, executor());
return new ElasticCaseService(elasticsearchTemplate, executor());
}

@Bean
@Primary
public IElasticTaskService elasticTaskService() {
return new ElasticTaskService(elasticsearchTemplate);
}
@Bean
public IElasticIndexService elasticIndexService() {
return new ElasticIndexService(elasticsearchTemplate);
}

@Bean
public IElasticCaseService reindexingTaskElasticCaseService() {
return new ElasticCaseService(caseRepository, elasticsearchTemplate, reindexingTaskCaseExecutor());
return new ElasticCaseService(elasticsearchTemplate, reindexingTaskCaseExecutor());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public String elasticUriIndex() {

@Bean
public RestHighLevelClient client() {

return new RestHighLevelClient(
RestClient.builder(new HttpHost(url, port, "http")));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,31 @@ public class CacheProperties {

private String petriNetCache = "petriNetCache";

private String caseIndexByNodeId = "caseIndexByNodeId";

private String caseIndexDynamic = "caseIndexDynamic";

private String caseIndexAll = "caseIndexAll";

private String caseIndexByMenuTaskId = "caseIndexByMenuTaskId";

private List<String> additional = new ArrayList<>();

public Set<String> getAllCaches() {
Set<String> caches = new LinkedHashSet<>(Arrays.asList(petriNetById, petriNetByIdentifier, petriNetNewest, petriNetCache));
List<String> cacheNames = Arrays.asList(
petriNetById,
petriNetByIdentifier,
petriNetNewest,
petriNetCache,
caseIndexByNodeId,
caseIndexDynamic,
caseIndexAll,
caseIndexByMenuTaskId
);

Set<String> caches = new LinkedHashSet<>(cacheNames);
caches.addAll(additional);
return caches;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.netgrif.application.engine.elastic.domain;


import com.netgrif.application.engine.elastic.web.requestbodies.CaseSearchRequest;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.*;

@NoArgsConstructor
public class IndexAwareElasticSearchRequest extends ArrayList<CaseSearchRequest> implements List<CaseSearchRequest> {

/**
* taskIds of task "view" in preference_menu_item (by default part of URL)
*/
@Getter
@Setter
private List<String> menuItemIds;

/**
* actual index name in elasticsearch
*/
@Getter
@Setter
private List<String> indexNames;

@Getter
@Setter
private boolean allIndex;

private IndexAwareElasticSearchRequest(List<String> menuItemIds, List<String> indexNames, Boolean allIndex) {
this.menuItemIds = menuItemIds;
this.indexNames = indexNames;
this.allIndex = Objects.requireNonNullElse(allIndex, false);
}

public static IndexAwareElasticSearchRequest all() {
return new IndexAwareElasticSearchRequest(null, null, true);
}

public static IndexAwareElasticSearchRequest ofIndex(String indexName) {
return new IndexAwareElasticSearchRequest(null, Collections.singletonList(indexName), false);
}

public static IndexAwareElasticSearchRequest ofIndexes(List<String> indexNames) {
return new IndexAwareElasticSearchRequest(null, Collections.unmodifiableList(indexNames), false);
}

public static IndexAwareElasticSearchRequest ofMenuItems(List<String> menuItemIds) {
return new IndexAwareElasticSearchRequest(Collections.unmodifiableList(Optional.ofNullable(menuItemIds).orElse(Collections.emptyList())), null, false);
}

public boolean doQueryAll() {
return this.allIndex;
}
}
Loading