Search in sources :

Example 1 with DockerImage

use of com.microsoft.azure.docker.model.DockerImage in project azure-tools-for-java by Microsoft.

the class DockerContainerNode method refreshItems.

@Override
protected void refreshItems() throws AzureCmdException {
    try {
        Map<String, DockerImage> dockerImages = AzureDockerImageOps.getImages(dockerHost);
        Map<String, DockerContainer> dockerContainers = AzureDockerContainerOps.getContainers(dockerHost);
        AzureDockerContainerOps.setContainersAndImages(dockerContainers, dockerImages);
        dockerHost.dockerImages = dockerImages;
        if (dockerContainers != null) {
            DockerContainer updatedDockerContainer = dockerContainers.get(dockerContainer.name);
            if (updatedDockerContainer != null) {
                dockerContainer = updatedDockerContainer;
                setDockerContainerIconPath();
            }
        }
    } catch (Exception e) {
        DefaultLoader.getUIHelper().logError(e.getMessage(), e);
    }
}
Also used : DockerContainer(com.microsoft.azure.docker.model.DockerContainer) DockerImage(com.microsoft.azure.docker.model.DockerImage) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)

Example 2 with DockerImage

use of com.microsoft.azure.docker.model.DockerImage in project azure-tools-for-java by Microsoft.

the class DockerHostNode method refreshDockerHostInstance.

private void refreshDockerHostInstance(VirtualMachine vm) {
    if (vm != null) {
        DockerHost updatedDockerHost = AzureDockerVMOps.getDockerHost(vm, dockerManager.getDockerVaultsMap());
        if (updatedDockerHost != null) {
            updatedDockerHost.sid = dockerHost.sid;
            updatedDockerHost.hostVM.sid = dockerHost.hostVM.sid;
            if (updatedDockerHost.certVault == null) {
                updatedDockerHost.certVault = dockerHost.certVault;
                updatedDockerHost.hasPwdLogIn = dockerHost.hasPwdLogIn;
                updatedDockerHost.hasSSHLogIn = dockerHost.hasSSHLogIn;
                updatedDockerHost.isTLSSecured = dockerHost.isTLSSecured;
            }
            dockerManager.updateDockerHost(updatedDockerHost);
            dockerHost = updatedDockerHost;
            if (dockerHost.certVault != null) {
                try {
                    // it might throw here if the credentials are invalid
                    Map<String, DockerImage> dockerImages = AzureDockerImageOps.getImages(dockerHost);
                    Map<String, DockerContainer> dockerContainers = AzureDockerContainerOps.getContainers(dockerHost);
                    AzureDockerContainerOps.setContainersAndImages(dockerContainers, dockerImages);
                    dockerHost.dockerImages = dockerImages;
                } catch (Exception e) {
                    DefaultLoader.getUIHelper().logError(e.getMessage(), e);
                }
            }
            setIconPath(getDockerHostIcon());
            for (DockerImage dockerImage : updatedDockerHost.dockerImages.values()) {
                try {
                    addChildNode(new DockerImageNode(this, dockerManager, updatedDockerHost, dockerImage));
                } catch (Exception ignored) {
                }
            }
        }
    }
}
Also used : DockerContainer(com.microsoft.azure.docker.model.DockerContainer) DockerHost(com.microsoft.azure.docker.model.DockerHost) DockerImage(com.microsoft.azure.docker.model.DockerImage) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)

Example 3 with DockerImage

use of com.microsoft.azure.docker.model.DockerImage in project azure-tools-for-java by Microsoft.

the class DockerContainerNode method loadActions.

@Override
protected void loadActions() {
    addAction(ACTION_OPEN_WEB_APP, DOCKER_CONTAINER_WEB_RUN_ICON, new NodeActionListener() {

        @Override
        public void actionPerformed(NodeActionEvent e) {
            DefaultLoader.getIdeHelper().runInBackground(null, "Open Web Link", false, true, "Opening Web Link...", new Runnable() {

                @Override
                public void run() {
                    if (dockerContainer.url != null && dockerContainer.isRunning && dockerHost.dockerImages.get(dockerContainer.image).isPluginImage) {
                        DefaultLoader.getIdeHelper().openLinkInBrowser(dockerContainer.url);
                    }
                }
            });
        }
    });
    addAction(ACTION_STOP, ACTION_STOP_ICON, new NodeActionListener() {

        @Override
        public void actionPerformed(NodeActionEvent e) {
            DefaultLoader.getIdeHelper().runInBackground(null, "Stopping Docker Container", false, true, "Stopping Docker Container...", new Runnable() {

                @Override
                public void run() {
                    AzureDockerContainerOps.stop(dockerContainer, dockerHost.session);
                    dockerContainer.isRunning = false;
                    setDockerContainerIconPath();
                }
            });
        }
    });
    addAction(ACTION_START, ACTION_START_ICON, new NodeActionListener() {

        @Override
        public void actionPerformed(NodeActionEvent e) {
            DefaultLoader.getIdeHelper().runInBackground(null, "Starting Docker Container", false, true, "Starting Docker Container...", new Runnable() {

                @Override
                public void run() {
                    AzureDockerContainerOps.start(dockerContainer, dockerHost.session);
                    dockerContainer.isRunning = true;
                    DockerImage dockerImage = dockerHost.dockerImages.get(dockerContainer.image);
                    if (dockerImage != null) {
                        if (dockerImage.artifactFile != null && !dockerImage.artifactFile.isEmpty()) {
                            // adjust the Url path to capture the artifact name
                            String url = dockerImage.artifactFile.toLowerCase().matches(".*\\.war") ? dockerContainer.url + dockerImage.artifactFile.substring(0, dockerImage.artifactFile.lastIndexOf(".")) : dockerContainer.url;
                            try {
                                // Give some time for the container to start
                                Thread.sleep(5000);
                            } catch (Exception ignored) {
                            }
                            if (dockerContainer.isRunning && checkDockerContainerUrlAvailability(url)) {
                                dockerContainer.url = url;
                            }
                        }
                    }
                    setDockerContainerIconPath();
                }
            });
        }
    });
    addAction(ACTION_RESTART, ACTION_START_ICON, new NodeActionListener() {

        @Override
        public void actionPerformed(NodeActionEvent e) {
            DefaultLoader.getIdeHelper().runInBackground(null, "Restarting Docker Container", false, true, "Restarting Docker Container...", new Runnable() {

                @Override
                public void run() {
                    AzureDockerContainerOps.stop(dockerContainer, dockerHost.session);
                    AzureDockerContainerOps.start(dockerContainer, dockerHost.session);
                    dockerContainer.isRunning = true;
                    setDockerContainerIconPath();
                }
            });
        }
    });
    addAction(ACTION_DELETE, ACTION_DELETE_ICON, new DeleteDockerContainerAction());
    super.loadActions();
}
Also used : DockerImage(com.microsoft.azure.docker.model.DockerImage) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)

Aggregations

DockerImage (com.microsoft.azure.docker.model.DockerImage)3 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)3 DockerContainer (com.microsoft.azure.docker.model.DockerContainer)2 DockerHost (com.microsoft.azure.docker.model.DockerHost)1