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

Cloud Assets - build and push docker command #7642

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
44 changes: 44 additions & 0 deletions enterprise/cloud.oracle/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,50 @@
<specification-version>1.57</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.maven</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>2</release-version>
<specification-version>2.165</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.maven.embedder</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>2</release-version>
<specification-version>2.77</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.execution</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>9.29</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.gradle</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>2</release-version>
<specification-version>2.42</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.libs.javax.inject</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>2</release-version>
<specification-version>2.61</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.project.dependency</code-name-base>
<build-prerequisite/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.netbeans.modules.cloud.oracle.actions;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectInformation;
import org.netbeans.api.project.ProjectUtils;
import org.netbeans.modules.cloud.oracle.assets.OpenProjectsFinder;
import org.netbeans.modules.cloud.oracle.assets.Steps;
import org.netbeans.modules.cloud.oracle.compartment.CompartmentItem;
import org.netbeans.modules.cloud.oracle.items.OCIItem;
import org.netbeans.modules.cloud.oracle.requests.ContainerRepositoryRequest;
import org.netbeans.modules.cloud.oracle.requests.OCIItemCreationDetails;
import org.netbeans.modules.cloud.oracle.steps.CompartmentStep;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.util.NbBundle;

/**
*
* @author Dusan Petrovic
*/

@NbBundle.Messages({
"CreateContainerRepository=Create new container repository",
"EnterName=Enter OCI resource name"
})
public class CreateContainerRepository implements OCIItemCreator {

private static final String REPOSITORY_NAME_FIELD = "name";

@Override
public CompletableFuture<? extends OCIItem> create(Steps.Values values, Map<String, Object> params) {
String compartmentId = ((CompartmentItem)values.getValueForStep(CompartmentStep.class)).getKey().getValue();
String displayName = (String) params.get(REPOSITORY_NAME_FIELD);
OCIItemCreationDetails creationDetails = new ContainerRepositoryRequest(compartmentId, displayName);
return new org.netbeans.modules.cloud.oracle.actions.CreateContainerRepositoryCommand().create(creationDetails);
}

@Override
public CompletableFuture<Map<String, Object>> steps() {
Map<String, Object> result = new HashMap<>();
CompletableFuture future = new CompletableFuture();

String suggestedName = getSuggestedName(future);
NotifyDescriptor.InputLine ci = new NotifyDescriptor.InputLine(Bundle.EnterName(), Bundle.EnterName());

if (suggestedName != null) {
ci.setInputText(suggestedName);
}

DialogDisplayer.getDefault().notifyFuture(ci).handle((r, exception) -> {
result.put(REPOSITORY_NAME_FIELD, r.getInputText());

if (exception != null) {
future.completeExceptionally(exception);
} else {
future.complete(result);
}
return null;
});
return future;
}

private String getSuggestedName(CompletableFuture future) {
CompletableFuture<Project[]> projects = OpenProjectsFinder.getDefault().findTopLevelProjects();
ProjectInformation pi = null;
try {
Project[] p = projects.get();
if (p != null && p.length > 0) {
pi = ProjectUtils.getInformation(p[0]);
}
} catch (InterruptedException | ExecutionException ex) {
future.completeExceptionally(ex);
}
return pi == null ? null : pi.getDisplayName();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.netbeans.modules.cloud.oracle.actions;

import com.oracle.bmc.artifacts.ArtifactsClient;
import com.oracle.bmc.artifacts.model.ContainerRepository;
import com.oracle.bmc.artifacts.requests.CreateContainerRepositoryRequest;
import com.oracle.bmc.artifacts.responses.CreateContainerRepositoryResponse;
import org.netbeans.modules.cloud.oracle.developer.ContainerRepositoryItem;
import org.netbeans.modules.cloud.oracle.items.OCID;
import org.netbeans.modules.cloud.oracle.requests.OCIItemCreationDetails;

/**
*
* @author Dusan Petrovic
*/
public class CreateContainerRepositoryCommand extends CreateResourceCommand<ContainerRepositoryItem> {

@Override
ContainerRepositoryItem callCreate(OCIItemCreationDetails itemCreator) {
ArtifactsClient client = this.getProfile().newClient(ArtifactsClient.class);

CreateContainerRepositoryRequest request = (CreateContainerRepositoryRequest) itemCreator.getRequest();
CreateContainerRepositoryResponse response = client.createContainerRepository(request);
ContainerRepository res = response.getContainerRepository();

return new ContainerRepositoryItem(
OCID.of(res.getId(), "ContainerRepository"), //NOI18N
res.getCompartmentId(),
res.getDisplayName(),
this.getProfile().getRegion().getRegionCode(),
res.getNamespace(),
res.getIsPublic(),
res.getImageCount()
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.netbeans.modules.cloud.oracle.actions;

import java.util.concurrent.CompletableFuture;
import org.netbeans.modules.cloud.oracle.OCIManager;
import org.netbeans.modules.cloud.oracle.OCISessionInitiator;
import org.netbeans.modules.cloud.oracle.items.OCIItem;
import org.netbeans.modules.cloud.oracle.requests.OCIItemCreationDetails;

/**
*
* @author Dusan Petrovic
*/
public abstract class CreateResourceCommand<T extends OCIItem> {

private final OCISessionInitiator profile;

public CreateResourceCommand() {
this.profile = OCIManager.getDefault().getActiveProfile();
}

public OCISessionInitiator getProfile() {
return profile;
}

abstract T callCreate(OCIItemCreationDetails itemCreator);

public CompletableFuture<T> create(OCIItemCreationDetails creationDetails) {
CompletableFuture future = new CompletableFuture();

try {
T item = callCreate(creationDetails);
future.complete(item);
} catch (Exception ex) {
future.completeExceptionally(ex);
}
return future;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.netbeans.modules.cloud.oracle.actions;

import java.util.Map;
import java.util.concurrent.CompletableFuture;
import org.netbeans.modules.cloud.oracle.assets.Steps;
import org.netbeans.modules.cloud.oracle.items.OCIItem;

/**
*
* @author Dusan Petrovic
*/
public interface OCIItemCreator {

CompletableFuture<Map<String, Object>> steps();

CompletableFuture<? extends OCIItem> create(Steps.Values values, Map<String, Object> params);

public static OCIItemCreator getCreator(String itemType) {
switch (itemType) {
case "ContainerRepository":
return new CreateContainerRepository();
default:
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@
import java.util.concurrent.CompletableFuture;
import org.netbeans.api.project.Project;
import org.netbeans.modules.cloud.oracle.actions.AddADBAction;
import org.netbeans.modules.cloud.oracle.actions.OCIItemCreator;
import org.netbeans.modules.cloud.oracle.database.DatabaseItem;
import org.netbeans.modules.cloud.oracle.steps.ItemTypeStep;
import org.netbeans.modules.cloud.oracle.items.OCIItem;
import org.netbeans.modules.cloud.oracle.steps.DatabaseConnectionStep;
import org.netbeans.modules.cloud.oracle.steps.ItemCreationDecisionStep;
import org.netbeans.modules.cloud.oracle.steps.TenancyStep;
import org.netbeans.spi.lsp.CommandProvider;
import org.openide.util.lookup.Lookups;
Expand Down Expand Up @@ -73,24 +75,41 @@ public CompletableFuture<Object> runCommand(String command, List<Object> argumen
.stepForClass(ItemTypeStep.class, (s) -> {
if ("Databases".equals(s.getValue())) {
return new DatabaseConnectionStep();
}
}
return new TenancyStep();
}).stepForClass(TenancyStep.class, (s) -> new CompartmentStep())
.stepForClass(CompartmentStep.class, (s) -> new SuggestedStep(null))
.stepForClass(CompartmentStep.class, (s) -> new ItemCreationDecisionStep())
.stepForClass(ItemCreationDecisionStep.class, (s) -> {
if (ItemCreationDecisionStep.CREATE_NEW_OPTION.equals(s.getValue())) {
return null;
}
return new SuggestedStep(null);
})
.stepForClass(SuggestedStep.class, (s) -> new ProjectStep())
.build();

Steps.getDefault()
.executeMultistep(new ItemTypeStep(), Lookups.fixed(nsProvider))
.thenAccept(values -> {
Project project = values.getValueForStep(ProjectStep.class);
CompletableFuture<? extends OCIItem> item;
if ("Databases".equals(values.getValueForStep(ItemTypeStep.class))) {
CompletableFuture<? extends OCIItem> item = null;
String itemType = values.getValueForStep(ItemTypeStep.class);
if ("Databases".equals(itemType)) {
DatabaseItem i = values.getValueForStep(DatabaseConnectionStep.class);
if (i == null) {
item = new AddADBAction().addADB();
} else {
item = CompletableFuture.completedFuture(i);
}
} else if (ItemCreationDecisionStep.CREATE_NEW_OPTION.equals(values.getValueForStep(ItemCreationDecisionStep.class))) { //NOI18N
OCIItemCreator creator = OCIItemCreator.getCreator(itemType);
if (creator != null) {
CompletableFuture<Map<String, Object>> vals = creator.steps();
item = vals.thenCompose(params -> {
return creator.create(values, params);
});
}

} else {
OCIItem i = values.getValueForStep(SuggestedStep.class);
if (i == null) {
Expand All @@ -100,6 +119,7 @@ public CompletableFuture<Object> runCommand(String command, List<Object> argumen
item = CompletableFuture.completedFuture(i);
}
}

item.thenAccept(i -> {
CloudAssets.getDefault().addItem(i);
String[] art = DEP_MAP.get(i.getKey().getPath());
Expand All @@ -113,5 +133,5 @@ public CompletableFuture<Object> runCommand(String command, List<Object> argumen
});
return future;
}

}
Loading
Loading