Skip to content

Commit

Permalink
IM-457 Add EngineProperties to Modeler. Manage activeProfiles.
Browse files Browse the repository at this point in the history
Introduced EngineProperties to the Modeler for enhanced configuration management. (Scanpackage)
Modified handling of activeProfiles to treat them as a list.
Removed unused code to improve maintainability and clarity.
  • Loading branch information
kristinaBc3 committed Dec 4, 2024
1 parent 819e787 commit ede5b75
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.integratedmodelling.klab.engine.rest.controllers.base;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand All @@ -24,20 +27,30 @@ public class EnvironmentController {
private static final String KEYCLOAK_URL = "KEYCLOAK_URL";
private static final String ACTIVE_PROFILE = "ACTIVE_PROFILE";

private static final String ENGINE_REMOTE = "engine.remote";
private static final String ENGINE_LOCAL = "engine.local";

@GetMapping(value = "/engine/environments")
public void getEnvironmentVariables(HttpServletRequest request, HttpServletResponse response) throws IOException {

response.setContentType("text/javascript;utf-8");

String activeProfile = System.getProperty("spring.profiles.active", "engine.local");

List<String> activeProfiles = Pattern.compile(",").splitAsStream(System.getProperty("spring.profiles.active", "unknown"))
.collect(Collectors.toList());

String activeProfile = activeProfiles.contains(ENGINE_REMOTE) ? ENGINE_REMOTE : ENGINE_LOCAL;

/*
* Get engine properties
*/
Map<String, String> kHubEnvironmentVariables = Map.ofEntries(Map.entry(APP_BASE_URL, engineProperties.env.getAppBaseUrl()),
Map.entry(KEYCLOAK_URL, engineProperties.env.getKeycloakUrl()), Map.entry(ACTIVE_PROFILE, activeProfile));


Map<String, String> kHubEnvironmentVariables = new HashMap<>();

if (activeProfile.equals(ENGINE_REMOTE)) {
kHubEnvironmentVariables = Map.ofEntries(Map.entry(APP_BASE_URL, engineProperties.env.getAppBaseUrl()),
Map.entry(KEYCLOAK_URL, engineProperties.env.getKeycloakUrl()), Map.entry(ACTIVE_PROFILE, activeProfile));
} else {
kHubEnvironmentVariables = Map.ofEntries(Map.entry(ACTIVE_PROFILE, activeProfile));
}

ObjectMapper objectMapper = new ObjectMapper();
String jsonValue = objectMapper.writeValueAsString(kHubEnvironmentVariables);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"org.integratedmodelling.klab.engine.rest.controllers.engine",
"org.integratedmodelling.klab.engine.rest.controllers.network",
"org.integratedmodelling.klab.engine.rest.messaging",
"org.integratedmodelling.klab.engine.rest.controllers.resources" })
"org.integratedmodelling.klab.engine.rest.controllers.resources",
"org.integratedmodelling.klab.engine.rest.api"})
public class Modeler implements ApplicationListener<ApplicationReadyEvent> {

private static Engine engine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ public class HubUserService implements RemoteUserService {

@Autowired
RestTemplate restTemplate;

@Value("${spring.profiles.active}")
private String activeProfile;

/*
* Generates a response entity a url to the session generated after succesful
Expand All @@ -74,7 +71,6 @@ public class HubUserService implements RemoteUserService {
public ResponseEntity< ? > login(RemoteUserAuthenticationRequest login) {
ResponseEntity<HubLoginResponse> result = null;
if (!"".equals(login.getUsername()) && null==login.getToken()) {
// if (activeProfile.equals("engine.remote")) {
login.setRemote(true);
try {
result = hubLogin(login);
Expand Down

0 comments on commit ede5b75

Please sign in to comment.