本文整理匯總了Java中io.fabric8.api.Container類的典型用法代碼示例。如果您正苦於以下問題:Java Container類的具體用法?Java Container怎麽用?Java Container使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Container類屬於io.fabric8.api包,在下文中一共展示了Container類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: removeProfileVersion
import io.fabric8.api.Container; //導入依賴的package包/類
@Override
public ProfileVersion removeProfileVersion(VersionIdentity version) {
assertValid();
// Lock for composite operation
LockHandle writeLock = aquireWriteLock(version);
try {
ContainerRegistry cntRegistry = containerRegistry.get();
ContainerLockManager lockManager = containerLocks.get();
for (ContainerIdentity cntid : cntRegistry.getContainerIdentities()) {
LockHandle readLock = lockManager.aquireReadLock(cntid);
try {
Container container = cntRegistry.getContainer(cntid);
VersionIdentity cntVersion = container.getProfileVersion();
IllegalStateAssertion.assertFalse(version.equals(cntVersion), "Cannot remove profile version used by: " + container);
} finally {
readLock.unlock();
}
}
ProfileRegistry registry = profileRegistry.get();
return registry.removeProfileVersion(version);
} finally {
writeLock.unlock();
}
}
示例2: removeProfile
import io.fabric8.api.Container; //導入依賴的package包/類
@Override
public Profile removeProfile(VersionIdentity version, ProfileIdentity profileId) {
assertValid();
// Lock for composite operation
LockHandle writeLock = aquireWriteLock(version);
try {
ContainerRegistry cntRegistry = containerRegistry.get();
ContainerLockManager lockManager = containerLocks.get();
for (ContainerIdentity cntid : cntRegistry.getContainerIdentities()) {
LockHandle readLock = lockManager.aquireReadLock(cntid);
try {
Container container = cntRegistry.getContainer(cntid);
IllegalStateAssertion.assertFalse(container.getProfileIdentities().contains(profileId), "Cannot remove profile used by: " + container);
} finally {
readLock.unlock();
}
}
ProfileRegistry registry = profileRegistry.get();
return registry.removeProfile(version, profileId);
} finally {
writeLock.unlock();
}
}
示例3: aquireWriteLock
import io.fabric8.api.Container; //導入依賴的package包/類
private LockHandle aquireWriteLock(ContainerIdentity identity) {
final AtomicReference<LockHandle> verLock = new AtomicReference<>();
final LockHandle cntLock = containerLocks.get().aquireWriteLock(identity);
try {
Container cnt = containerRegistry.get().getContainer(identity);
VersionIdentity version = cnt != null ? cnt.getProfileVersion() : null;
if (version != null) {
verLock.set(profileService.get().aquireWriteLock(version));
}
} catch (RuntimeException rte) {
safeUnlock(cntLock, verLock);
throw rte;
} catch (Error err) {
safeUnlock(cntLock, verLock);
throw err;
}
return new LockHandle() {
@Override
public void unlock() {
safeUnlock(cntLock, verLock);
}
};
}
示例4: aquireReadLock
import io.fabric8.api.Container; //導入依賴的package包/類
private LockHandle aquireReadLock(ContainerIdentity identity) {
final AtomicReference<LockHandle> verLock = new AtomicReference<>();
final LockHandle cntLock = containerLocks.get().aquireReadLock(identity);
try {
Container cnt = containerRegistry.get().getContainer(identity);
VersionIdentity version = cnt != null ? cnt.getProfileVersion() : null;
if (version != null) {
verLock.set(profileService.get().aquireReadLock(version));
}
} catch (RuntimeException rte) {
safeUnlock(cntLock, verLock);
throw rte;
} catch (Error err) {
safeUnlock(cntLock, verLock);
throw err;
}
return new LockHandle() {
@Override
public void unlock() {
safeUnlock(cntLock, verLock);
}
};
}
示例5: startContainerInternal
import io.fabric8.api.Container; //導入依賴的package包/類
private Container startContainerInternal(Container container, ProvisionEventListener listener) throws ProvisionException {
LOGGER.info("Start container: {}", container);
if (container.getProfileVersion() == null) {
Profile defaultProfile = profileService.get().getDefaultProfile();
setVersionInternal(container, defaultProfile.getVersion(), listener);
addProfilesInternal(container, Collections.singletonList(defaultProfile.getIdentity()), listener);
}
// Start the container
ContainerRegistry registry = containerRegistry.get();
container = registry.startContainer(container.getIdentity());
// Provision the container profiles
VersionIdentity version = container.getProfileVersion();
List<ProfileIdentity> identities = container.getProfileIdentities();
provisionProfilesInternal(container, version, identities, listener);
return container;
}
示例6: destroyContainer
import io.fabric8.api.Container; //導入依賴的package包/類
@Override
public Container destroyContainer(ContainerIdentity identity) {
assertValid();
IllegalStateAssertion.assertFalse(currentIdentity.equals(identity), "Cannot destroy current container");
if (isLocalContainer(identity)) {
LockHandle writeLock = aquireWriteLock(identity);
try {
Container container = getContainer(identity);
return destroyContainerInternal(container);
} finally {
writeLock.unlock();
}
} else {
ProcessIdentity procId = ProcessIdentity.create(identity.getSymbolicName());
ManagedProcess process = agent.get().destroyProcess(procId);
State state = State.valueOf(process.getState().toString());
Map<AttributeKey<?>, Object> attributes = process.getAttributes();
return new ImmutableContainer.Builder(identity, process.getRuntimeType(), attributes, state).build();
}
}
示例7: destroyContainerInternal
import io.fabric8.api.Container; //導入依賴的package包/類
private Container destroyContainerInternal(Container container) {
ContainerIdentity identity = container.getIdentity();
Set<ContainerIdentity> childIdentities = container.getChildIdentities();
IllegalStateAssertion.assertTrue(childIdentities.isEmpty(), "Cannot destroy a container that has active child containers: " + container);
// Stop the container
if (container.getState() == State.STARTED) {
container = stopContainer(identity);
}
LOGGER.info("Destroy container: {}", container);
ContainerRegistry registry = containerRegistry.get();
ContainerIdentity parentId = container.getParentIdentity();
if (parentId != null) {
LockHandle parentLock = aquireWriteLock(parentId);
try {
registry.removeChildFromParent(parentId, identity);
} finally {
parentLock.unlock();
}
}
return registry.destroyContainer(container.getIdentity());
}
示例8: getEffectiveProfileInternal
import io.fabric8.api.Container; //導入依賴的package包/類
private Profile getEffectiveProfileInternal(Container container, VersionIdentity version, List<ProfileIdentity> profiles) {
LockHandle readLock = aquireReadLock(container.getIdentity());
try {
StringBuffer effectiveId = new StringBuffer("effective#" + version);
for (ProfileIdentity prfid : profiles) {
effectiveId.append("-" + prfid.getSymbolicName());
}
ProfileBuilder prfBuilder = new DefaultProfileBuilder(effectiveId.toString());
prfBuilder.profileVersion(version);
for (ProfileIdentity profileId : profiles) {
LinkedProfile linkedProfile = profileService.get().getLinkedProfile(version, profileId);
ProfileUtils.buildEffectiveProfile(prfBuilder, linkedProfile);
}
return prfBuilder.getProfile();
} finally {
readLock.unlock();
}
}
示例9: activateInternal
import io.fabric8.api.Container; //導入依賴的package包/類
private void activateInternal() throws IOException {
Path dataPath = runtimeService.get().getDataPath();
workspace = dataPath.resolve("profiles");
repository = new GitRepository(workspace);
// Add the default profile version
if (!repository.hasBranch(DEFAULT_PROFILE_VERSION.getVersion())) {
Profile profile = new DefaultProfileBuilder(DEFAULT_PROFILE_IDENTITY)
.addConfigurationItem(Container.CONTAINER_SERVICE_PID, Collections.singletonMap("config.token", (Object) "default"))
.getProfile();
LinkedProfileVersion profileVersion = new DefaultProfileVersionBuilder(DEFAULT_PROFILE_VERSION)
.addProfile(profile)
.getProfileVersion();
addProfileVersionInternal(profileVersion);
}
}
示例10: storeInternal
import io.fabric8.api.Container; //導入依賴的package包/類
private void storeInternal(Container container) {
LOGGER.debug("Storing container {}.", container.getIdentity());
ContainerIdentity identity = container.getIdentity();
String id = identity.getSymbolicName();
Container existing = getContainer(identity);
try {
if (existing == null) {
curator.get().create().creatingParentsIfNeeded().forPath(ZkPath.CONTAINER.getPath(id));
}
setParentInternal(identity, container.getParentIdentity());
setChildIdentitiesInternal(identity, container.getChildIdentities());
setRuntimeTypeInternal(identity, container.getRuntimeType());
setProfilesInternal(identity, container.getProfileIdentities());
setVersionInternal(identity, container.getProfileVersion());
setAttributesInternal(ZkPath.CONTAINER_ATTRIBUTES.getPath(id), container.getAttributes());
setStateInternal(identity, container.getState());
setServiceEndpointsInternal(identity, container.getServiceEndpoints());
} catch (Exception e) {
throw FabricException.launderThrowable(e);
}
}
示例11: readInternal
import io.fabric8.api.Container; //導入依賴的package包/類
private Container readInternal(ContainerIdentity identity) {
LOGGER.debug("Reading container {}.", identity);
Container result = null;
String id = identity.getSymbolicName();
try {
if (curator.get().checkExists().forPath(ZkPath.CONTAINER.getPath(id)) != null) {
ContainerIdentity parentIdentity = getParentInternal(identity);
Map<AttributeKey<?>, Object> attributes = getAttributesInternal(ZkPath.CONTAINER_ATTRIBUTES.getPath(id));
RuntimeType type = getRuntimeTypeInternal(identity);
List<ProfileIdentity> profiles = getProfileIdentities(identity);
VersionIdentity version = getVersionInternal(identity);
State state = getStateInternal(identity);
Set<ContainerIdentity> children = getChildIdentitiesInternal(identity);
Set<ServiceEndpoint> endpoints = getServiceEndpointsInternal(identity);
result = new ImmutableContainer.Builder(identity, type, attributes, state).addProfiles(profiles).addProfileVersion(version).addParent(parentIdentity)
.addChildren(children).addServiceEndpoints(endpoints).build();
}
} catch (Exception ex) {
throw FabricException.launderThrowable(ex);
}
return result;
}
示例12: testManagedKaraf
import io.fabric8.api.Container; //導入依賴的package包/類
@Test
@Ignore
public void testManagedKaraf() throws Exception {
// Build the {@link CreateOptions}
Runtime runtime = RuntimeLocator.getRequiredRuntime();
File dataDir = new File((String) runtime.getProperty(RuntimeService.RUNTIME_DATA_DIR));
CreateOptions options = KarafContainerBuilder.create()
.identity("ManagedKaraf")
.outputToConsole(true)
.targetPath(dataDir.toPath())
.getCreateOptions();
ContainerManager cntManager = ContainerManagerLocator.getContainerManager();
Container cnt = cntManager.createContainer(options);
ContainerIdentity cntId = cnt.getIdentity();
try {
// Start the container
cnt = cntManager.startContainer(cntId, null);
verifyContainer(cnt);
} finally {
cnt = cntManager.stopContainer(cntId);
Assert.assertEquals(State.STOPPED, cnt.getState());
}
}
示例13: activateInternal
import io.fabric8.api.Container; //導入依賴的package包/類
private void activateInternal() throws Exception {
String runtimeId = RuntimeIdentity.getIdentity();
AgentIdentity agentId = AgentIdentity.create(runtimeId);
// Register this Agent
Container cnt = currentContainer.get().getCurrentContainer();
ServiceEndpoint jmxsep = cnt.getServiceEndpoint(JMX_SERVICE_ENDPOINT_IDENTITY);
String jmxEndpoint = jmxsep.adapt(URLServiceEndpoint.class).getServiceURL();
ServiceEndpoint jolokiasep = cnt.getServiceEndpoint(JOLOKIA_SERVICE_ENDPOINT_IDENTITY);
String jolokiaEndpoint = jolokiasep.adapt(URLServiceEndpoint.class).getServiceURL();
String targetHost = networkProvider.get().getIp();
String runtimeType = RuntimeType.getRuntimeType().toString();
localAgent = new AgentRegistration(agentId, runtimeType, targetHost, jmxEndpoint, jolokiaEndpoint);
agentTopology.get().addAgentRegistration(localAgent);
LOGGER.info("Bootstrap agent: {}", localAgent);
// Register this agent with the cluster
registerAgentWithCluster(localAgent);
}
示例14: doExecute
import io.fabric8.api.Container; //導入依賴的package包/類
@Override
protected Object doExecute() throws Exception {
if (tick <= 0) {
tick = TimeUnit.SECONDS.toMillis(5);
}
if (wait <= 0) {
wait = TimeUnit.MINUTES.toMillis(1);
}
log.trace("Checking status of {} for {} every {}ms until {}ms.", status, containerName, tick, wait);
Container container = FabricCommand.getContainer(fabricService, containerName);
Boolean hasTimedOut;
if (status.equals(ContainerStartedPredicate.STARTED)) {
hasTimedOut = waitForContainerStatus(container, new ContainerStartedPredicate(containerName, dataStore));
} else if (status.equals(ContainerStoppedPredicate.STOPPED)) {
hasTimedOut = waitForContainerStatus(container, new ContainerStoppedPredicate(containerName, dataStore));
} else {
throw new IllegalArgumentException("Status " + status + " does not exist. Expected '"
+ ContainerStartedPredicate.STARTED + "' or '" + ContainerStoppedPredicate.STOPPED + "'");
}
if (hasTimedOut) {
throw new TimeoutException("Took longer than wait value");
}
return null;
}
示例15: waitForContainerStatus
import io.fabric8.api.Container; //導入依賴的package包/類
protected Boolean waitForContainerStatus(Container container, StatusPredicate predicate) throws InterruptedException {
Boolean hasTimedOut = false;
Long currentTime = System.nanoTime();
Long waitTimeout = currentTime + TimeUnit.MILLISECONDS.toNanos(wait);
while (!hasTimedOut) {
Boolean isComplete = predicate.matches(container);
if (isComplete) {
log.trace("{} matches status {}", containerName, status);
break;
}
currentTime = System.nanoTime();
if (currentTime > waitTimeout) {
log.trace("{} status took too long. Current time {}ns is greater than wait {}ns", containerName, currentTime, waitTimeout);
hasTimedOut = true;
break;
}
//Probably not the best way, but does its job
TimeUnit.MILLISECONDS.sleep(tick);
}
printContainerStatus(container, predicate);
return hasTimedOut;
}