Skip to content

Commit

Permalink
Updated way output folder is hosted
Browse files Browse the repository at this point in the history
  • Loading branch information
bpmweel committed Aug 15, 2018
1 parent 97fbaff commit dc6ae73
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 28 deletions.
@@ -1,7 +1,5 @@
package nl.esciencecenter.computeservice.config;

import javax.validation.constraints.NotNull;

import com.fasterxml.jackson.annotation.JsonProperty;

import nl.esciencecenter.xenon.credentials.Credential;
Expand All @@ -21,19 +19,6 @@ public TargetAdaptorConfig(Credential credential) {
super(credential);
}

@NotNull
public String getBaseurl() {
return baseurl;
}

public void setBaseurl(String baseurl) {
if (baseurl == null) {
this.baseurl = "output";
} else {
this.baseurl = baseurl;
}
}

public boolean isHosted() {
return hosted;
}
Expand Down
Expand Up @@ -33,6 +33,7 @@
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

Expand Down Expand Up @@ -74,11 +75,15 @@ public class Application extends WebSecurityConfigurerAdapter implements WebMvcC
@Value("${xenonflow.admin.location}")
private String adminLocation;

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**");
}

@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
APIKeyAuthFilter filter = new APIKeyAuthFilter(principalRequestHeader);
filter.setAuthenticationManager(new AuthenticationManager() {

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String principal = (String) authentication.getPrincipal();
Expand All @@ -102,10 +107,18 @@ public Authentication authenticate(Authentication authentication) throws Authent
.antMatchers(HttpMethod.HEAD,"/jobs/**").permitAll() //allow CORS option calls
.antMatchers(HttpMethod.OPTIONS,"/files/**").permitAll()//allow CORS option calls
.antMatchers(HttpMethod.HEAD,"/files/**").permitAll() //allow CORS option calls
.antMatchers(HttpMethod.OPTIONS,"/output/**").permitAll()//allow CORS option calls
.antMatchers(HttpMethod.HEAD,"/output/**").permitAll() //allow CORS option calls
.antMatchers(HttpMethod.OPTIONS,"/status/**").permitAll()//allow CORS option calls
.antMatchers(HttpMethod.HEAD,"/status/**").permitAll() //allow CORS option calls
.antMatchers("/jobs").authenticated()
.antMatchers("/jobs/**").authenticated()
.antMatchers("/files").authenticated()
.antMatchers("/files/**").authenticated()
.antMatchers("/jobs/**").authenticated()
.antMatchers("/output").authenticated()
.antMatchers("/output/**").authenticated()
.antMatchers("/status").authenticated()
.antMatchers("/status/**").authenticated()
.antMatchers("/**").permitAll();
}

Expand All @@ -132,8 +145,8 @@ public static XenonStager remoteToTargetStager(XenonService xenonService, JobRep
return new XenonStager(jobService, repository, xenonService.getRemoteFileSystem(), xenonService.getTargetFileSystem(), xenonService);
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
@Bean
public TargetAdaptorConfig targetFileSystemConfig() {
String xenonflowHome = System.getenv("XENONFLOW_HOME");

if (xenonflowHome == null) {
Expand All @@ -142,16 +155,23 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
ComputeServiceConfig config;
try {
config = ComputeServiceConfig.loadFromFile(xenonConfigFile, xenonflowHome);
TargetAdaptorConfig targetConfig = config.getTargetFilesystemConfig();

if (targetConfig.isHosted() && targetConfig.getAdaptor().equals("file")) {
String resourceLocation = targetConfig.getBaseurl() + "/**";
logger.info("Adding resource location handler for: " + resourceLocation);
registry.addResourceHandler(resourceLocation).addResourceLocations("file:" + targetConfig.getLocation());
}
return config.getTargetFilesystemConfig();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
TargetAdaptorConfig targetConfig = targetFileSystemConfig();
if (targetConfig.isHosted() && targetConfig.getAdaptor().equals("file")) {
String resourceLocation = "/output/**";
logger.info("Adding resource location handler for: " + resourceLocation);
registry.addResourceHandler(resourceLocation)
.addResourceLocations("file:" + targetConfig.getLocation());
}

registry.addResourceHandler("/swagger/**")
.addResourceLocations("classpath:/META-INF/resources/");

Expand Down
Expand Up @@ -312,7 +312,7 @@ public WorkflowBinding postStageout(Job job, StagingManifest manifest) throws IO
UriComponentsBuilder b;
if (service.getConfig().getTargetFilesystemConfig().isHosted()) {
b = UriComponentsBuilder.fromUriString(manifest.getBaseurl());
b.pathSegment(service.getConfig().getTargetFilesystemConfig().getBaseurl());
b.pathSegment("output/");
b.pathSegment(manifest.getTargetDirectory().resolve(object.getTargetPath()).toString());
} else {
b = UriComponentsBuilder.fromUriString(targetFileSystem.getLocation().toString());
Expand Down Expand Up @@ -391,7 +391,7 @@ public void fixDirectoryStagingObject(Job job, StagingManifest manifest,
UriComponentsBuilder b;
if (service.getConfig().getTargetFilesystemConfig().isHosted()) {
b = UriComponentsBuilder.fromUriString(manifest.getBaseurl());
b.pathSegment(service.getConfig().getTargetFilesystemConfig().getBaseurl());
b.pathSegment("output/");
b.pathSegment(manifest.getTargetDirectory().resolve(object.getTargetPath()).toString());
} else {
b = UriComponentsBuilder.fromUriString(targetFileSystem.getLocation().toString());
Expand Down

0 comments on commit dc6ae73

Please sign in to comment.