Skip to content

Commit

Permalink
merge from main
Browse files Browse the repository at this point in the history
  • Loading branch information
srnagar committed Jul 9, 2024
2 parents 889bd44 + 1f39d28 commit eb76106
Show file tree
Hide file tree
Showing 46 changed files with 2,226 additions and 599 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ public AzureEventHubsResource(String name) {
// return DistributedApplication.getInstance().addValue(new AzureEventHubsResource(name, this));
// }

@Override
public List<EndpointReference> getEndpoints() {
// TODO how do I know which endpoints are available?
return List.of();
}

@Override
public List<TemplateFileOutput> processTemplate(Path outputPath) {
final String templatePath = "/templates/bicep/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.microsoft.aspire.resources.AzureBicepResource;
import com.microsoft.aspire.resources.properties.EndpointReference;
import com.microsoft.aspire.resources.properties.ReferenceExpression;
import com.microsoft.aspire.resources.traits.ResourceWithConnectionString;
import com.microsoft.aspire.resources.traits.ResourceWithEndpoints;
import com.microsoft.aspire.utils.templates.TemplateEngine;
Expand Down Expand Up @@ -33,12 +33,6 @@ public AzureOpenAIResource withDeployment(AzureOpenAIDeployment deployment) {
return this;
}

@Override
public List<EndpointReference> getEndpoints() {
// TODO how do I know which endpoints are available?
return List.of();
}

@Override
public List<TemplateFileOutput> processTemplate(Path outputPath) {
final String templatePath = "/templates/openai/bicep/";
Expand All @@ -58,13 +52,40 @@ public List<TemplateFileOutput> processTemplate(Path outputPath) {
return templateOutput;
}

// @Override
// public String getConnectionStringEnvironmentVariable() {
// return "connectionString";
// }

// @JsonIgnore
// @Override
// public String getValueExpression() {
// return "HELLOWORLD";
// }
//
// @Override
// public ReferenceExpression getConnectionStringExpression() {
// // FIXME
// return ReferenceExpression.create("{" + getName() + ".outputs.connectionString}");
// }

// @Override
// public String getValue() {
// return "{" + getName() + ".outputs.connectionString}";
// }



@Override
public String getConnectionStringEnvironmentVariable() {
return "connectionString";
public ReferenceExpression getConnectionStringExpression() {
// FIXME duplicated below
return ReferenceExpression.create("{" + getName() + ".outputs.connectionString}");
}

@JsonIgnore
@Override
public String getValue() {
public String getValueExpression() {
// FIXME
return "{" + getName() + ".outputs.connectionString}";
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
package com.microsoft.aspire.extensions.azure.storage.resources;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.microsoft.aspire.resources.properties.ReferenceExpression;

public final class AzureStorageBlobsResource extends AzureStorageChildResource {

public AzureStorageBlobsResource(String name, AzureStorageResource storageResource) {
super(name, storageResource, "blobEndpoint");
super(name, storageResource);
}

@Override
public ReferenceExpression getConnectionStringExpression() {
// FIXME duplicated below
return ReferenceExpression.create("{" + storageResource.getName() + ".outputs.blobEndpoint}");
}

@JsonIgnore
@Override
public String getValueExpression() {
// FIXME
return "{" + storageResource.getName() + ".outputs.blobEndpoint}";
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
package com.microsoft.aspire.extensions.azure.storage.resources;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.microsoft.aspire.resources.Resource;
import com.microsoft.aspire.resources.ResourceType;
import com.microsoft.aspire.resources.properties.ReferenceExpression;
import com.microsoft.aspire.resources.traits.ResourceWithConnectionString;
import com.microsoft.aspire.resources.traits.ResourceWithParent;

public class AzureStorageChildResource extends Resource<AzureStorageChildResource>
implements ResourceWithConnectionString<AzureStorageChildResource>,
public abstract class AzureStorageChildResource extends Resource<AzureStorageChildResource>
implements ResourceWithConnectionString<AzureStorageChildResource>,
ResourceWithParent<AzureStorageResource> {
private final AzureStorageResource storageResource;
private final String endpointSuffix;
final AzureStorageResource storageResource;
// private final String endpointSuffix;
// private final ReferenceExpression connectionStringExpression;

public AzureStorageChildResource(String name, AzureStorageResource storageResource, String endpointSuffix) {
AzureStorageChildResource(String name, AzureStorageResource storageResource) {
super(ResourceType.VALUE, name);
this.storageResource = storageResource;
this.endpointSuffix = endpointSuffix;
// this.endpointSuffix = endpointSuffix;
// this.connectionStringExpression = connectionStringExpression;
}

@Override
public AzureStorageResource getParent() {
return storageResource;
}

@Override
public String getConnectionStringEnvironmentVariable() {
return "connectionString";
}
// @Override
// public String getConnectionStringEnvironmentVariable() {
// return "connectionString";
// }

@Override
public String getValue() {
// FIXME this kind of concatenation is error prone
return "{" + storageResource.getName() + ".outputs." + endpointSuffix + "}";
}


// @Override
// public String getValue() {
// // FIXME this kind of concatenation is error prone
// return "{" + storageResource.getName() + ".outputs." + endpointSuffix + "}";
// }

@Override
public AzureStorageChildResource self() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
package com.microsoft.aspire.extensions.azure.storage.resources;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.microsoft.aspire.resources.properties.ReferenceExpression;

public final class AzureStorageQueuesResource extends AzureStorageChildResource {

public AzureStorageQueuesResource(String name, AzureStorageResource storageResource) {
super(name, storageResource, "queueEndpoint");
super(name, storageResource);
}

@Override
public ReferenceExpression getConnectionStringExpression() {
// FIXME duplicated below
return ReferenceExpression.create("{" + storageResource.getName() + ".outputs.queueEndpoint}");
}

@JsonIgnore
@Override
public String getValueExpression() {
// FIXME
return "{" + storageResource.getName() + ".outputs.queueEndpoint}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.microsoft.aspire.resources.AzureBicepResource;
import com.microsoft.aspire.resources.ResourceType;
import com.microsoft.aspire.resources.properties.EndpointReference;
import com.microsoft.aspire.resources.properties.ReferenceExpression;
import com.microsoft.aspire.resources.traits.ResourceWithEndpoints;
import com.microsoft.aspire.utils.templates.TemplateEngine;

Expand All @@ -15,6 +16,22 @@ public class AzureStorageResource extends AzureBicepResource<AzureStorageResourc
implements ResourceWithEndpoints<AzureStorageResource> {
private static final ResourceType AZURE_STORAGE = ResourceType.fromString("azure.bicep.v0");

// internal ReferenceExpression GetTableConnectionString() => IsEmulator
// ? ReferenceExpression.Create($"{AzureStorageEmulatorConnectionString.Create(tablePort: EmulatorTableEndpoint.Port)}")
// : ReferenceExpression.Create($"{TableEndpoint}");
//
// internal ReferenceExpression GetQueueConnectionString() => IsEmulator
// ? ReferenceExpression.Create($"{AzureStorageEmulatorConnectionString.Create(queuePort: EmulatorQueueEndpoint.Port)}")
// : ReferenceExpression.Create($"{QueueEndpoint}");
//
// internal ReferenceExpression GetBlobConnectionString() => IsEmulator
// ? ReferenceExpression.Create($"{AzureStorageEmulatorConnectionString.Create(blobPort: EmulatorBlobEndpoint.Port)}")
// : ReferenceExpression.Create($"{BlobEndpoint}");

// static final ReferenceExpression TABLE_CONNECTION_STRING = ReferenceExpression.create("tableEndpoint");
// static final ReferenceExpression QUEUE_CONNECTION_STRING = ReferenceExpression.create("queueEndpoint");
// static final ReferenceExpression BLOB_CONNECTION_STRING = ReferenceExpression.create("blobEndpoint");

public AzureStorageResource(String name) {
super(AZURE_STORAGE, name);
withParameter("principalId", "");
Expand All @@ -33,12 +50,6 @@ public AzureStorageTablesResource addTables(String name) {
return DistributedApplication.getInstance().addResource(new AzureStorageTablesResource(name, this));
}

@Override
public List<EndpointReference> getEndpoints() {
// TODO how do I know which endpoints are available?
return List.of();
}

@Override
public List<TemplateFileOutput> processTemplate(Path outputPath) {
final String templatePath = "/templates/bicep/";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
package com.microsoft.aspire.extensions.azure.storage.resources;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.microsoft.aspire.resources.properties.ReferenceExpression;

public final class AzureStorageTablesResource extends AzureStorageChildResource {

public AzureStorageTablesResource(String name, AzureStorageResource storageResource) {
super(name, storageResource, "tableEndpoint");
super(name, storageResource);
}

@Override
public ReferenceExpression getConnectionStringExpression() {
// FIXME duplicated below
return ReferenceExpression.create("{" + storageResource.getName() + ".outputs.tableEndpoint}");
}

@JsonIgnore
@Override
public String getValueExpression() {
// FIXME
return "{" + storageResource.getName() + ".outputs.tableEndpoint}";
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.microsoft.aspire.extensions.spring.resources;

import com.microsoft.aspire.resources.DockerFile;
import com.microsoft.aspire.resources.properties.Binding;
import com.microsoft.aspire.resources.traits.ResourceWithEndpoints;
import com.microsoft.aspire.resources.traits.ResourceWithTemplate;
import com.microsoft.aspire.utils.templates.TemplateEngine;

Expand All @@ -11,14 +11,15 @@
import java.util.Map;

public final class EurekaServiceDiscovery extends DockerFile<EurekaServiceDiscovery>
implements ResourceWithTemplate<EurekaServiceDiscovery> {
implements ResourceWithTemplate<EurekaServiceDiscovery>,
ResourceWithEndpoints<EurekaServiceDiscovery> {

private final String PROPERTY_NAME = "name";
private final String PROPERTY_PORT = "port";
private final String PROPERTY_TARGET_PORT = "targetPort";
private final String PROPERTY_REGISTER_WITH_EUREKA = "registerWithEureka";
private final String PROPERTY_FETCH_REGISTRY = "fetchRegistry";

private static final int DEFAULT_PORT = 8761;
private static final int DEFAULT_TARGET_PORT = 8761;

private final Map<String, Object> properties;

Expand All @@ -27,20 +28,18 @@ public EurekaServiceDiscovery(String name) {

this.properties = new HashMap<>();
this.properties.put(PROPERTY_NAME, name);
this.properties.put(PROPERTY_PORT, DEFAULT_PORT);
this.properties.put(PROPERTY_TARGET_PORT, DEFAULT_TARGET_PORT);
this.properties.put(PROPERTY_REGISTER_WITH_EUREKA, false);
this.properties.put(PROPERTY_FETCH_REGISTRY, false);

withPort(DEFAULT_PORT);
withPort(DEFAULT_TARGET_PORT);
}

public EurekaServiceDiscovery withPort(int port) {
this.properties.put(PROPERTY_PORT, port);
public EurekaServiceDiscovery withPort(int targetPort) {
this.properties.put(PROPERTY_TARGET_PORT, targetPort);

withBinding(new Binding(Binding.Scheme.HTTP, Binding.Protocol.TCP, Binding.Transport.HTTP)
/*.withPort(port)*/.withTargetPort(port).withExternal());
withBinding(new Binding(Binding.Scheme.HTTPS, Binding.Protocol.TCP, Binding.Transport.HTTP)
/*.withPort(port)*/.withTargetPort(port).withExternal());
withHttpEndpoint(targetPort);
withHttpsEndpoint(targetPort);

return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import com.microsoft.aspire.resources.DockerFile;
import com.microsoft.aspire.resources.Project;
import com.microsoft.aspire.resources.ResourceType;
import com.microsoft.aspire.resources.properties.Binding;
import com.microsoft.aspire.resources.properties.Protocol;
import com.microsoft.aspire.resources.properties.Scheme;
import com.microsoft.aspire.resources.properties.Transport;
import com.microsoft.aspire.resources.traits.IntrospectiveResource;
import jakarta.validation.Valid;

Expand All @@ -27,8 +29,10 @@ public SpringProject(String name) {
withEnvironment("spring.application.name", name);

// FIXME this should be removed once the introspector supports discovering the bindings
withBinding(new Binding(Binding.Scheme.HTTP, Binding.Protocol.TCP, Binding.Transport.HTTP).withTargetPort(8080));
withBinding(new Binding(Binding.Scheme.HTTPS, Binding.Protocol.TCP, Binding.Transport.HTTP).withTargetPort(8080));
// withBinding(new Binding(Scheme.HTTP, Protocol.TCP, Transport.HTTP).withTargetPort(8080));
// withBinding(new Binding(Scheme.HTTPS, Protocol.TCP, Transport.HTTP).withTargetPort(8080));
withHttpEndpoint(8080);
// withHttpsEndpoint(8080);
}

@Override
Expand All @@ -49,6 +53,7 @@ public void introspect() {
.findFirst().ifPresent(s -> {
// we need to set the service name (to the existing spring project name), the path to the Dockerfile, and the
// context name (which is the directory containing the Dockerfile)
// FIXME ugly generics
DockerFile<?> dockerFile = new DockerFile<>(getName());

String dockerFilePath = s.getCommands().get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ spring:
application:
name: ${name}
server:
port: ${port?c}
port: ${targetPort?c}
eureka:
instance:
hostname: localhost
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.microsoft.aspire;

import com.microsoft.aspire.resources.*;
import com.microsoft.aspire.resources.traits.IntrospectiveResource;
import jakarta.validation.Valid;

import java.io.PrintStream;
Expand Down
Loading

0 comments on commit eb76106

Please sign in to comment.