use of io.fabric8.kubernetes.api.model.Context in project carbon-apimgt by wso2.
the class KubernetesGatewayImplTestCase method testCreateContainerGatewayForAlreadyAvailableResources.
@Test
public void testCreateContainerGatewayForAlreadyAvailableResources() 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);
BaseOperation baseOperation = Mockito.mock(BaseOperation.class);
String serviceName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX + ContainerBasedGatewayConstants.CMS_SERVICE_SUFFIX;
Mockito.when(openShiftClient.services().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
Mockito.when(nonNamespaceOperation.withName(serviceName)).thenReturn(baseOperation);
Service service = Mockito.mock(Service.class, Mockito.RETURNS_DEEP_STUBS);
Mockito.when(baseOperation.get()).thenReturn(service);
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);
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(scalableResource);
Ingress ingress = Mockito.mock(Ingress.class, Mockito.RETURNS_DEEP_STUBS);
Mockito.when(scalableResource.get()).thenReturn(deployment, ingress);
API api = SampleTestObjectCreator.createDefaultAPI().context("/test/context/").build();
kubernetesGateway.createContainerGateway(ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX, api);
Mockito.verify(openShiftClient, Mockito.times(4)).load(Mockito.any());
Mockito.verify(openShiftClient, Mockito.times(2)).services();
Mockito.verify(openShiftClient, Mockito.times(4)).extensions();
}
use of io.fabric8.kubernetes.api.model.Context in project carbon-apimgt by wso2.
the class KubernetesGatewayImplTestCase method testCreateServiceResourceForKubernetesClientException.
@Test
public void testCreateServiceResourceForKubernetesClientException() 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());
NonNamespaceOperation nonNamespaceOperationService = Mockito.mock(NonNamespaceOperation.class);
BaseOperation baseOperationService = Mockito.mock(BaseOperation.class);
String serviceName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX + ContainerBasedGatewayConstants.CMS_SERVICE_SUFFIX;
Mockito.when(openShiftClient.services().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperationService);
Mockito.when(nonNamespaceOperationService.withName(serviceName)).thenReturn(baseOperationService);
Mockito.when(baseOperationService.get()).thenThrow(KubernetesClientException.class);
API api = SampleTestObjectCreator.createDefaultAPI().context("").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);
}
}
use of io.fabric8.kubernetes.api.model.Context in project fabric8 by jboss-fuse.
the class JolokiaFabricConnector method connect.
/**
* connects to a fabric
*/
public void connect() {
if (this.j4p != null || this.fabricServiceFacade != null) {
disconnect();
}
this.j4p = J4pClient.url(this.url).user(this.userName).password(this.password).build();
/* This needs further investigation...
DefaultHttpClient httpClient = (DefaultHttpClient) j4p.getHttpClient();
httpClient.setRedirectStrategy(new DefaultRedirectStrategy() {
@Override
public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
return true;
}
});
*/
this.fabricServiceFacade = new FabricServiceFacade(this);
this.fabricMBeanFacade = new FabricMBean(this);
}
use of io.fabric8.kubernetes.api.model.Context in project fabric8 by jboss-fuse.
the class AetherBasedResolver method collectDependencies.
protected DependencyNode collectDependencies(Artifact root, String pomVersion, final Filter<Dependency> excludeDependencyFilter) throws RepositoryException, IOException {
final DefaultRepositorySystemSession session = newSession();
try {
List<RemoteRepository> repos = selectRepositories();
assignProxyAndMirrors(repos);
ArtifactDescriptorResult artifactDescriptorResult = m_repoSystem.readArtifactDescriptor(session, new ArtifactDescriptorRequest(root, repos, null));
repos.addAll(artifactDescriptorResult.getRepositories());
Dependency rootDependency = new Dependency(root, null);
List<Dependency> dependencies = artifactDescriptorResult.getDependencies();
final DefaultDependencyNode rootNode = new DefaultDependencyNode(rootDependency);
GenericVersionScheme versionScheme = new GenericVersionScheme();
rootNode.setVersion(versionScheme.parseVersion(pomVersion));
rootNode.setVersionConstraint(versionScheme.parseVersionConstraint(pomVersion));
DependencyNode pomNode = rootNode;
// final Filter<Dependency> shouldExclude = Filters.or(DependencyFilters.testScopeFilter, excludeDependencyFilter, new NewerVersionExistsFilter(rootNode));
final Filter<Dependency> shouldExclude = Filters.or(Arrays.asList(DependencyFilters.testScopeFilter, excludeDependencyFilter));
DependencySelector dependencySelector = new AndDependencySelector(new ScopeDependencySelector("test"), new ExclusionDependencySelector(), new DependencySelector() {
@Override
public DependencySelector deriveChildSelector(DependencyCollectionContext context) {
return this;
}
@Override
public boolean selectDependency(Dependency dependency) {
try {
return !DependencyFilters.matches(dependency, shouldExclude);
} catch (Exception e) {
failedToMakeDependencyTree(dependency, e);
return false;
}
}
});
session.setDependencySelector(dependencySelector);
// work on the root dependency directly?
if (true) {
for (Dependency dependency : dependencies) {
DependencyNode node = resolveDependencies(session, repos, pomNode, dependency, shouldExclude);
if (node != null) {
pomNode.getChildren().add(node);
}
}
} else {
DependencyNode node = resolveDependencies(session, repos, pomNode, rootDependency, shouldExclude);
if (node != null) {
pomNode = node;
}
}
// now lets transform the dependency tree to remove different versions for the same artifact
final DependencyGraphTransformationContext tranformContext = new DependencyGraphTransformationContext() {
Map<Object, Object> map = new HashMap<>();
public RepositorySystemSession getSession() {
return session;
}
public Object get(Object key) {
return map.get(key);
}
public Object put(Object key, Object value) {
return map.put(key, value);
}
};
DependencyGraphTransformer transformer = new ReplaceConflictingVersionResolver();
pomNode = transformer.transformGraph(pomNode, tranformContext);
transformer = new DuplicateTransformer();
pomNode = transformer.transformGraph(pomNode, tranformContext);
return pomNode;
} finally {
releaseSession(session);
}
}
use of io.fabric8.kubernetes.api.model.Context in project fabric8 by jboss-fuse.
the class DummyBatchingProgressMonitor method gitOperation.
@Override
public <T> T gitOperation(GitContext context, GitOperation<T> gitop, PersonIdent personIdent) {
IllegalArgumentAssertion.assertNotNull(gitop, "gitop");
IllegalArgumentAssertion.assertNotNull(context, "context");
LockHandle writeLock = aquireWriteLock();
try {
assertValid();
LOGGER.debug("External call to execute a git operation: " + gitop);
return executeInternal(context, personIdent, gitop);
} finally {
writeLock.unlock();
}
}
Aggregations