Skip to content
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

feat: first draft of Infrastructure API and related models #407

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
de27e9d
resolved cyclic JPMS issues, compilation works now
deepak-swirlds Oct 12, 2023
1d12ff6
implementing changes suggested by Nathan, saving progress
deepak-swirlds Oct 19, 2023
83550d0
Removing model classes from fullstack-models
deepak-swirlds Oct 19, 2023
054bc1b
added Labeled, added exec() method
deepak-swirlds Oct 20, 2023
778fecd
spotless apply
deepak-swirlds Oct 23, 2023
f8ff9b5
saving progress
deepak-swirlds Nov 2, 2023
0365b0f
spotless apply
deepak-swirlds Nov 2, 2023
e989515
some code cleanup and documentation
deepak-swirlds Nov 2, 2023
f9cb990
merged ! after a frustrating session
deepak-swirlds Nov 3, 2023
c105624
fixed build erorr
deepak-swirlds Nov 3, 2023
554616e
removed fullstack-models, moved the packages into fullstack-configura…
deepak-swirlds Nov 3, 2023
49ab8a0
removed accidentally checked-in files and fixed test configuration
deepak-swirlds Nov 3, 2023
733db73
moving examples inside a named java package
deepak-swirlds Nov 3, 2023
000a32d
address review comments
deepak-swirlds Nov 3, 2023
6d24925
Merge branch 'main' into 301-infra-api-first-draft
deepak-swirlds Nov 6, 2023
81a6f18
Merge branch 'main' into 301-infra-api-first-draft
nathanklick Nov 7, 2023
ec41dd1
moving concrete classes from api -> core
deepak-swirlds Nov 7, 2023
8793437
java docs on exception classes
deepak-swirlds Nov 7, 2023
5c84a7b
minor code changes to address review comments
deepak-swirlds Nov 8, 2023
d90c3bb
Merge remote-tracking branch 'origin/main' into 301-infra-api-first-d…
deepak-swirlds Nov 8, 2023
3c72b56
added javadocs as per review comments
deepak-swirlds Nov 8, 2023
3f5677a
fix compilation errors in examples
deepak-swirlds Nov 9, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ plugins {
javaModuleDependencies {
moduleNameToGA.put("com.hedera.fullstack.junit.support", "com.hedera.fullstack:fullstack-junit-support")
moduleNameToGA.put("com.hedera.fullstack.test.toolkit", "com.hedera.fullstack:fullstack-test-toolkit")
moduleNameToGA.put("com.hedera.fullstack.base.api", "com.hedera.fullstack:fullstack-base-api")
moduleNameToGA.put("com.hedera.fullstack.readiness.api", "com.hedera.fullstack:fullstack-readiness-api")
moduleNameToGA.put("com.hedera.fullstack.monitoring.api", "com.hedera.fullstack:fullstack-monitoring-api")
moduleNameToGA.put("com.hedera.fullstack.validator.api", "com.hedera.fullstack:fullstack-validator-api")
Expand Down
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
* limitations under the License.
*/

package com.hedera.fullstack.infrastructure.api.providers;
package com.hedera.fullstack.configuration.model;

public interface InfrastructureManager {}
public enum InstallType {
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved
NMT,
DIRECT_INSTALL
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2023 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.fullstack.configuration.model;

/**
* A container class to hold all configuration needed to hold the NetworkDeployment
*/
public class NetworkDeploymentConfiguration {

// FUTURE: This class needs to closely reflect what will be passed in values.yaml

InstallType installType;
Topology topology;
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (C) 2023 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.fullstack.configuration.model;

public record Node(int ram, int cpu, int nodeID, int nodeAccountID) {}
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

package com.hedera.fullstack.infrastructure.core;
package com.hedera.fullstack.configuration.model;

public class Dummy {}
import java.util.List;

public record Topology(List<Node> nodes) {}
jeromy-cannon marked this conversation as resolved.
Show resolved Hide resolved
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module com.hedera.fullstack.configuration.api {}
module com.hedera.fullstack.configuration.api {
exports com.hedera.fullstack.configuration.model;
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ plugins {

dependencies {
api(platform(project(":fullstack-bom")))
implementation(project(mapOf("path" to ":fullstack-helm-client")))
implementation(project(":fullstack-helm-client"))
implementation(project(":fullstack-configuration-api"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (C) 2023 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.fullstack.infrastructure.api.exceptions;

public class DeploymentLimitReachedException extends Exception {}
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (C) 2023 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.fullstack.infrastructure.api.exceptions;

public class InfrastructureException extends Exception {}
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* limitations under the License.
*/

package com.hedera.fullstack.resource.generator.api;
package com.hedera.fullstack.infrastructure.api.exceptions;

public class Dummy {}
public class InstallationException extends Exception {}
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (C) 2023 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.fullstack.infrastructure.api.exceptions;

public class InvalidConfigurationException extends Exception {}
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (C) 2023 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.fullstack.infrastructure.api.exceptions;

public class NetworkDeploymentNotFoundException extends Exception {}
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (C) 2023 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.fullstack.infrastructure.api.manager;

import com.hedera.fullstack.configuration.model.NetworkDeploymentConfiguration;
import com.hedera.fullstack.infrastructure.api.exceptions.DeploymentLimitReachedException;
import com.hedera.fullstack.infrastructure.api.exceptions.InfrastructureException;
import com.hedera.fullstack.infrastructure.api.exceptions.InvalidConfigurationException;
import com.hedera.fullstack.infrastructure.api.exceptions.NetworkDeploymentNotFoundException;
import com.hedera.fullstack.infrastructure.api.model.NetworkDeployment;
import java.util.List;
import java.util.concurrent.Future;

/**
* InfrastructureManager is the main entry point into infrastructure management for FST <br/>
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved
* <br/>
* Responsibilities:
* <ol>
* <li> Manages the lifecycle of a {@link NetworkDeployment}</li>
* <li> Acts as a registry for all {@link NetworkDeployment}s created by it</li></li>
* </ol>
*
* <hr/>
* <strong> About NetworkDeployments </strong>
* <p>
* A {@link NetworkDeployment} represents all the workloads and their components needed for a Hedera ecosystem. <br/>
* Upon instantiation, the {@link NetworkDeployment} object can interact with its workloads and components directly

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Codacy found a minor Code Style issue: Line is longer than 80 characters (found 115).

The issue identified by Checkstyle is that the line of code exceeds the maximum preferred line length of 80 characters, which is a common code style guideline to improve readability. Long lines of code can be difficult to read, especially in environments with limited screen space or when viewing multiple files side by side.

To fix this issue, you can break the long comment line into two or more lines, ensuring that each line does not exceed 80 characters. Here's how you can modify the comment:

Suggested change
* Upon instantiation, the {@link NetworkDeployment} object can interact with its workloads and components directly
* Upon instantiation, the {@link NetworkDeployment} object can interact with
* its workloads and components directly and does not need {@link InfrastructureManager}.

By splitting the comment into two lines, each line now adheres to the 80-character limit, which should resolve the Checkstyle warning for line length.


This comment was generated by an experimental AI tool.

* and does not need {@link InfrastructureManager}.
* </p>
*/
public interface InfrastructureManager {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to most likely be a singleton and therefore may be better served as a concrete final class which uses a ServiceLocator implementation to load the provider.

Another option would be to use the enum singleton pattern recommended by Joshua Bloch in his book Effective Java.


default NetworkDeployment createNetworkDeployment(NetworkDeploymentConfiguration hederaNetwork)
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved
throws InvalidConfigurationException, DeploymentLimitReachedException, InfrastructureException {
return null;
}

/**
* Creates the {@link NetworkDeployment} based on the {@link NetworkDeploymentConfiguration} provided.
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved
* This is a long running process, expected time is in the order of a few minutes.
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved
* Note: the {@link NetworkDeployment} can be spread across multiple clusters and cloud providers.
*/
Future<NetworkDeployment> createNetworkDeploymentAsync(NetworkDeploymentConfiguration hederaNetwork)
throws InvalidConfigurationException, DeploymentLimitReachedException, InfrastructureException;

/**
* List all the {@link NetworkDeployment}s created by this InfrastructureManager
* TODO: --> @return a list of {@link NetworkDeployment}s
*/
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved
List<NetworkDeployment> listNetworkDeployments();

/**
* Returns the {@link NetworkDeployment} with the given id
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved
* @param id Unique identifier of the {@link NetworkDeployment}, the implementation
* will usually be a combination of namespace, job name and job id etc.
* @return the {@link NetworkDeployment} with the given id
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved
* @throws NetworkDeploymentNotFoundException
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved
*/
NetworkDeployment networkDeploymentById(String id) throws NetworkDeploymentNotFoundException;
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved

/**
* Deletes the {@link NetworkDeployment} with the given id and all its workload replicas and components
* @param id Unique identifier of the {@link NetworkDeployment}, the implementation
* will usually be a combination of namespace, job name and job id etc.
* @return true if the {@link NetworkDeployment} was deleted successfully, false otherwise
* @throws NetworkDeploymentNotFoundException
*/
Future<Boolean> deleteNetworkDeployment(String id) throws NetworkDeploymentNotFoundException;
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2023 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.fullstack.infrastructure.api.model;

import java.util.List;

public class AbstractWorkload<T extends Workload> implements Workload {
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved

List<WorkloadReplica<T>> replicas;
Cluster cluster;
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved

@Override
public Cluster cluster() {
return cluster;
}

@Override
public List<WorkloadReplica<T>> replicas() {
return replicas;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2023 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.fullstack.infrastructure.api.model;

import com.hedera.fullstack.infrastructure.api.traits.KubernetesAware;
import java.util.List;

/**
* A {@link Cluster}
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved
*
* <ul>
* <li>is a set of physical or virtual machines which can be used to deploy {@link Workload}s</li>
* <li>can be a public or private cloud, or a bare metal cluster in any geography</li>
* <li>can host a subset of or all of the{@link Workload}s within a {@link NetworkDeployment}</li>
* <li> must be able to expose the {@link Component}s (ones which need) of {@link Workload}s in way that its
* reachable from {@link Component}s hosted on other {@link Cluster}s</li>
* </ul>
*/
public interface Cluster extends KubernetesAware {

/**
* @return the {@link Workload}s hosted on this {@link Cluster}
*/
List<Workload> listWorkloads();

/**
* @return the {@link Workload} hosted on this {@link Cluster} of the given type
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved
*/
<T extends Workload> T findWorkloadByType(Class<T> workloadType);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2023 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.fullstack.infrastructure.api.model;

import com.hedera.fullstack.configuration.model.NetworkDeploymentConfiguration;
import com.hedera.fullstack.infrastructure.api.traits.Labeled;

// only individual classes will implement PodAware and ServiceAware
public interface Component extends Labeled {
deepak-swirlds marked this conversation as resolved.
Show resolved Hide resolved

// lifecycle
// this should be mostly done by helm
default void init() {}

default void configure(NetworkDeploymentConfiguration deploymentNetworkDeploymentConfiguration) {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Codacy found a minor Code Style issue: Line is longer than 80 characters (found 102).

The code provided contains a method signature that exceeds the 80-character line length limit enforced by the Checkstyle linter. This is a common code style guideline meant to improve readability and maintainability of the code, especially on smaller screens or when viewing multiple files side by side.

To fix this issue, you can break the line into multiple lines. Here's an example of how you might format the method to comply with the 80-character limit:

default void configure(
    NetworkDeploymentConfiguration deploymentNetworkDeploymentConfiguration) {}

By breaking the line after the configure(, you ensure that each line stays within the 80-character limit. You might also consider renaming the parameter to a shorter name if it's still too long, or if the context allows for it without losing clarity.

Here's the code suggestion with a shorter parameter name:

Suggested change
default void configure(NetworkDeploymentConfiguration deploymentNetworkDeploymentConfiguration) {}
default void configure(NetworkDeploymentConfig config) {}

Remember to update the Javadoc comments accordingly if you change the parameter name.


This comment was generated by an experimental AI tool.


default void destroy() {}
}
Loading