Search in sources :

Example 11 with Deployment

use of io.fabric8.kubernetes.api.model.apps.Deployment in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method testCreateIngressResourceForKubernetesException.

@Test
public void testCreateIngressResourceForKubernetesException() throws Exception {
    OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
    KubernetesGatewayImpl kubernetesGateway = getKubernetesGatewayImpl(openShiftClient);
    Mockito.when(openShiftClient.load(Mockito.any()).get()).thenReturn(getServiceResources(), getDeploymentResources(), getIngressResources());
    NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
    ScalableResource scalableResource = Mockito.mock(ScalableResource.class);
    Mockito.when(scalableResource.get()).thenReturn(null);
    Service service = createService(openShiftClient, nonNamespaceOperation);
    Deployment deployment = createDeployment(openShiftClient, nonNamespaceOperation, scalableResource);
    Mockito.when(nonNamespaceOperation.create(Mockito.any())).thenReturn(service, deployment);
    ScalableResource scalableResourceIngress = Mockito.mock(ScalableResource.class);
    String ingressName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX + ContainerBasedGatewayConstants.CMS_INGRESS_SUFFIX;
    Mockito.when(openShiftClient.extensions().ingresses().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
    Mockito.when(nonNamespaceOperation.withName(ingressName)).thenReturn(scalableResourceIngress);
    Mockito.when(scalableResourceIngress.get()).thenThrow(KubernetesClientException.class);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    try {
        kubernetesGateway.createContainerGateway(ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX, api);
    } catch (ContainerBasedGatewayException e) {
        Assert.assertEquals(e.getErrorHandler(), ExceptionCodes.DEDICATED_CONTAINER_GATEWAY_CREATION_FAILED);
    }
}
Also used : ScalableResource(io.fabric8.kubernetes.client.dsl.ScalableResource) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Service(io.fabric8.kubernetes.api.model.Service) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) API(org.wso2.carbon.apimgt.core.models.API) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.junit.Test)

Example 12 with Deployment

use of io.fabric8.kubernetes.api.model.apps.Deployment in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method createDeployment.

/**
 * Create Deployment resource
 *
 * @param openShiftClient       Openshift client
 * @param nonNamespaceOperation NonNamespaceOperation instance
 * @param scalableResource      ScalableResource instance
 */
private Deployment createDeployment(OpenShiftClient openShiftClient, NonNamespaceOperation nonNamespaceOperation, ScalableResource scalableResource) {
    String deploymentName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX + ContainerBasedGatewayConstants.CMS_DEPLOYMENT_SUFFIX;
    Mockito.when(openShiftClient.extensions().deployments().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
    Mockito.when(nonNamespaceOperation.withName(deploymentName)).thenReturn(scalableResource);
    Deployment deployment = Mockito.mock(Deployment.class, Mockito.RETURNS_DEEP_STUBS);
    return deployment;
}
Also used : Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment)

Example 13 with Deployment

use of io.fabric8.kubernetes.api.model.apps.Deployment in project fabric8 by jboss-fuse.

the class DeploymentUpdater method updateDeployment.

public void updateDeployment(Git git, File baseDir, CredentialsProvider credentials) throws Exception {
    Set<String> bundles = new LinkedHashSet<String>();
    Set<Feature> features = new LinkedHashSet<Feature>();
    Profile overlayProfile = container.getOverlayProfile();
    Profile effectiveProfile = Profiles.getEffectiveProfile(fabricService, overlayProfile);
    bundles.addAll(effectiveProfile.getBundles());
    AgentUtils.addFeatures(features, fabricService, downloadManager, effectiveProfile);
    if (copyFilesIntoGit) {
        copyDeploymentsIntoGit(git, baseDir, bundles, features);
    } else {
        addDeploymentsIntoPom(git, baseDir, effectiveProfile, bundles, features);
    }
    // now lets do a commit
    String message = "updating deployment";
    git.commit().setMessage(message).call();
    enableDeployDirectory(git, baseDir);
    String branch = GitHelpers.currentBranch(git);
    LOG.info("Pushing deployment changes to branch " + branch + " credentials " + credentials + " for container " + container.getId());
    try {
        Iterable<PushResult> results = git.push().setCredentialsProvider(credentials).setRefSpecs(new RefSpec(branch)).setOutputStream(new LoggingOutputStream(LOG)).call();
        /*
            for (PushResult result : results) {
                LOG.info(result.getMessages());
            }
*/
        LOG.info("Pushed deployment changes to branch " + branch + " for container " + container.getId());
    } catch (GitAPIException e) {
        LOG.error("Failed to push deployment changes to branch " + branch + " for container " + container.getId() + ". Reason: " + e, e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) RefSpec(org.eclipse.jgit.transport.RefSpec) LoggingOutputStream(io.fabric8.common.util.LoggingOutputStream) PushResult(org.eclipse.jgit.transport.PushResult) Feature(io.fabric8.agent.model.Feature) Profile(io.fabric8.api.Profile)

Example 14 with Deployment

use of io.fabric8.kubernetes.api.model.apps.Deployment in project fabric8 by jboss-fuse.

the class MavenProxyResolutionTest method releaseIsAvailableInRemoteRepositoryNotUpdatingRelease.

@Test
public void releaseIsAvailableInRemoteRepositoryNotUpdatingRelease() throws IOException, InvalidMavenArtifactRequest {
    File remoteRepository = initFileRepository("rr");
    MavenResolver resolver = new ResolverBuilder().withRemoteRepositories(Collections.singletonList(remoteRepository)).withUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS).build();
    MavenDownloadProxyServlet servlet = new MavenDownloadProxyServlet(resolver, runtime, null, 1, 0);
    mvnInstall(remoteRepository, "io.fabric8.test", "universalis-api", "0.1.0", at("10:00"), "a");
    File file = servlet.download("io/fabric8/test/universalis-api/0.1.0/universalis-api-0.1.0.jar");
    // first resolution
    assertThat(FileUtils.readFileToString(file), equalTo("a"));
    // don't do that, it's not proper use of maven. But sometimes we just have another deployment to public repository...
    mvnInstall(remoteRepository, "io.fabric8.test", "universalis-api", "0.1.0", at("11:00"), "b");
    // second resolution
    file = servlet.download("io/fabric8/test/universalis-api/0.1.0/universalis-api-0.1.0.jar");
    assertThat("Artifact won't be updated for release version", FileUtils.readFileToString(file), equalTo("a"));
}
Also used : MavenResolver(io.fabric8.maven.MavenResolver) File(java.io.File) Test(org.junit.Test)

Example 15 with Deployment

use of io.fabric8.kubernetes.api.model.apps.Deployment in project fabric8 by jboss-fuse.

the class Deployer method logDeployment.

protected void logDeployment(Deployer.Deployment overallDeployment, int verbose) {
    if (overallDeployment.regions.isEmpty()) {
        print("No deployment change.", verbose);
        return;
    }
    print("Changes to perform:", verbose);
    for (Map.Entry<String, RegionDeployment> region : overallDeployment.regions.entrySet()) {
        Deployer.RegionDeployment deployment = region.getValue();
        print("  Region: " + region.getKey(), verbose);
        if (!deployment.toDelete.isEmpty()) {
            print("    Bundles to uninstall:", verbose);
            for (Bundle bundle : deployment.toDelete) {
                print("      " + bundle.getSymbolicName() + " / " + bundle.getVersion(), verbose);
            }
        }
        if (!deployment.toUpdate.isEmpty()) {
            print("    Bundles to update:", verbose);
            for (Map.Entry<Bundle, Resource> entry : deployment.toUpdate.entrySet()) {
                print("      " + entry.getKey().getSymbolicName() + " / " + entry.getKey().getVersion() + " with " + getUri(entry.getValue()), verbose);
            }
        }
        if (!deployment.toInstall.isEmpty()) {
            print("    Bundles to install:", verbose);
            for (Resource resource : deployment.toInstall) {
                print("      " + getUri(resource), verbose);
            }
        }
    }
}
Also used : Bundle(org.osgi.framework.Bundle) Resource(org.osgi.resource.Resource) FeatureResource(io.fabric8.agent.resolver.FeatureResource)

Aggregations

File (java.io.File)62 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)52 Test (org.testng.annotations.Test)50 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)47 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)43 Container (io.fabric8.kubernetes.api.model.Container)32 Service (io.fabric8.kubernetes.api.model.Service)28 Test (org.junit.Test)28 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)27 InputStream (java.io.InputStream)26 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)25 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)25 Deployment (org.jboss.arquillian.container.test.api.Deployment)21 OSGiManifestBuilder (org.jboss.osgi.metadata.OSGiManifestBuilder)21 Asset (org.jboss.shrinkwrap.api.asset.Asset)21 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)21 IOException (java.io.IOException)20 ServiceTracker (org.osgi.util.tracker.ServiceTracker)20 FileInputStream (java.io.FileInputStream)19 CommandSupport (io.fabric8.itests.support.CommandSupport)18