-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* added server endpoint to get profiles * change to switch score-client storage implementations * cleared azure and s3 related entries app.yml * some bug fixes and enhancements * updated comment * added test profile. * added test profile. * refactored code based on review comments - BaseController now returns a single profile value. The actual profile name and the profile value returned by the api are now different. * debug logging removed * replaced profile value * updated readme * updated readme * added a test profile * review changes - Storage profile values now come from an enum in score-core - test configuration created to mock storage profile bean - users will be able to provide a default profile value when working with old score-server instances * users will be able to provide a default profile value when working with old score-server instances * config change * added a test config in score server --------- Co-authored-by: UmmulkiramR <urangwala@oicr.on.ca>
- Loading branch information
1 parent
11337b5
commit 7c2fdce
Showing
17 changed files
with
411 additions
and
74 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
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
72 changes: 72 additions & 0 deletions
72
score-client/src/main/java/bio/overture/score/client/config/ProfileConfig.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,72 @@ | ||
package bio.overture.score.client.config; | ||
|
||
import bio.overture.score.client.exception.NotRetryableException; | ||
import bio.overture.score.core.model.StorageProfiles; | ||
import lombok.NonNull; | ||
import lombok.extern.slf4j.Slf4j; | ||
import lombok.val; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Configuration | ||
@Slf4j | ||
@ConditionalOnProperty(value="isTest", havingValue="false") | ||
public class ProfileConfig { | ||
|
||
@Autowired | ||
private RestTemplate serviceTemplate; | ||
|
||
@Value("${storage.url}") | ||
@NonNull | ||
private String endpoint; | ||
|
||
@Autowired | ||
@Value("${defaultProfile:collaboratory}") | ||
private String defaultProfile; | ||
|
||
@Autowired | ||
@Value("${isTest}") | ||
private boolean isTest = false; | ||
|
||
@Qualifier("clientVersion") | ||
@Autowired | ||
@NonNull | ||
String clientVersion; | ||
|
||
@Bean | ||
public String storageProfile(){ | ||
String profile = getStorageProfile(); | ||
return profile; | ||
} | ||
|
||
private String getStorageProfile() { | ||
log.debug("get profile endpoint: "+endpoint); | ||
try{ | ||
String storageProfile = serviceTemplate.exchange(endpoint + "/profile", HttpMethod.GET, defaultEntity(), String.class).getBody(); | ||
return storageProfile; | ||
}catch(NotRetryableException nre ){ | ||
log.error("received exception when getting profiles: " + nre.getMessage()); | ||
} | ||
return StorageProfiles.getProfileValue(defaultProfile); | ||
} | ||
|
||
|
||
private HttpEntity<Object> defaultEntity() { | ||
return new HttpEntity<Object>(defaultHeaders()); | ||
} | ||
|
||
private HttpHeaders defaultHeaders() { | ||
val requestHeaders = new HttpHeaders(); | ||
requestHeaders.add(HttpHeaders.USER_AGENT, clientVersion); | ||
return requestHeaders; | ||
} | ||
|
||
} |
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
31 changes: 31 additions & 0 deletions
31
score-client/src/main/java/bio/overture/score/client/util/BeanUtil.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,31 @@ | ||
package bio.overture.score.client.util; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.StringUtils; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
|
||
// utility class to inject beans dynamically at runtime | ||
|
||
@Component | ||
public class BeanUtil<T> { | ||
|
||
@Autowired | ||
ApplicationContext appContext; | ||
|
||
//this method injects beans dynamically based on score-server active profile | ||
public Object getBeanForProfile(Class cl){ | ||
String profile = appContext.getBean("storageProfile", String.class); | ||
|
||
Set<String> beans = appContext.getBeansOfType(cl).keySet(); | ||
return appContext.getBean(beans.stream() | ||
.filter(s -> s.equals(profile+cl.getSimpleName())) | ||
.collect(Collectors.toList()) | ||
.get(0), cl); | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
score-client/src/test/java/bio/overture/score/client/config/TestProfileConfig.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,26 @@ | ||
package bio.overture.score.client.config; | ||
|
||
import bio.overture.score.client.exception.NotRetryableException; | ||
import bio.overture.score.core.model.StorageProfiles; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.test.context.ContextConfiguration; | ||
|
||
@TestConfiguration | ||
public class TestProfileConfig { | ||
|
||
@Autowired | ||
@Value("${defaultProfile:collaboratory}") | ||
private String defaultProfile; | ||
|
||
@Bean | ||
public String storageProfile(){ | ||
return StorageProfiles.getProfileValue(defaultProfile); | ||
} | ||
|
||
} |
Oops, something went wrong.