use of com.vmware.xenon.common.FactoryService in project photon-model by vmware.
the class AuthCredentialsOperationProcessingChainTest method setUp.
@Override
@Before
public void setUp() throws Throwable {
// wait for needed services
waitForServiceAvailability(AuthCredentialsService.FACTORY_LINK);
// set AuthCredentialsOperationProcessingChain in the factory
FactoryService fs = (FactoryService) findService.invoke(host, AuthCredentialsService.FACTORY_LINK);
fs.setOperationProcessingChain(AuthCredentialsOperationProcessingChain.createOperationProcessingChain(fs));
// common setup
System.clearProperty(EncryptionUtils.ENCRYPTION_KEY);
System.clearProperty(EncryptionUtils.INIT_KEY_IF_MISSING);
EncryptionUtils.initEncryptionService();
}
use of com.vmware.xenon.common.FactoryService in project photon-model by vmware.
the class AWSComputeDiskDay2ServiceTest method setUp.
@Before
public void setUp() throws Exception {
CommandLineArgumentParser.parseFromProperties(this);
setAwsClientMockInfo(this.isAwsClientMock, this.awsMockEndpointReference);
AuthCredentialsService.AuthCredentialsServiceState creds = new AuthCredentialsService.AuthCredentialsServiceState();
creds.privateKey = this.secretKey;
creds.privateKeyId = this.accessKey;
TestContext ec2WaitContext = new TestContext(1, Duration.ofSeconds(30L));
AWSUtils.getEc2AsyncClient(creds, TestAWSSetupUtils.regionId, getExecutor()).exceptionally(t -> {
ec2WaitContext.fail(t);
throw new CompletionException(t);
}).thenAccept(ec2Client -> {
this.client = ec2Client;
ec2WaitContext.complete();
});
ec2WaitContext.await();
this.awsTestContext = new HashMap<>();
setUpTestVpc(this.client, this.awsTestContext, this.isMock, this.zoneId);
this.singleNicSpec = (TestAWSSetupUtils.AwsNicSpecs) this.awsTestContext.get(TestAWSSetupUtils.NIC_SPECS_KEY);
this.host = VerificationHost.create(0);
try {
this.host.setMaintenanceIntervalMicros(TimeUnit.MILLISECONDS.toMicros(250));
this.host.start();
PhotonModelServices.startServices(this.host);
PhotonModelAdaptersRegistryAdapters.startServices(this.host);
PhotonModelMetricServices.startServices(this.host);
PhotonModelTaskServices.startServices(this.host);
ServiceMetadata[] serviceMetadata = { factoryService(DiskTaskService.class, DiskTaskService::createFactory) };
StartServicesHelper.startServices(this.host, serviceMetadata);
AWSAdaptersTestUtils.startServicesSynchronously(this.host);
this.host.setTimeoutSeconds(1200);
this.host.waitForServiceAvailable(PhotonModelServices.LINKS);
this.host.waitForServiceAvailable(PhotonModelMetricServices.LINKS);
this.host.waitForServiceAvailable(PhotonModelTaskServices.LINKS);
initResourcePoolAndComputeHost(this.zoneId);
} catch (Throwable e) {
throw new Exception(e);
}
}
use of com.vmware.xenon.common.FactoryService in project photon-model by vmware.
the class BaseTestCase method verifyService.
protected void verifyService(URI factoryUri, FactoryService factoryInstance, Class<? extends ServiceDocument> serviceDocumentType, TestServiceDocumentInitialization serviceDocumentInit, TestServiceDocumentAssertion assertion) throws Throwable {
int childCount = 1;
TestContext ctx = testCreate(childCount);
String prefix = "example-";
URI[] childURIs = new URI[childCount];
for (int i = 0; i < childCount; i++) {
ServiceDocument serviceDocument = serviceDocumentInit.create(prefix, i);
final int finalI = i;
// create a ServiceDocument instance.
Operation createPost = createForcedPost(factoryUri).setBody(serviceDocument).setCompletion((o, e) -> {
if (e != null) {
ctx.failIteration(e);
return;
}
ServiceDocument rsp = o.getBody(serviceDocumentType);
childURIs[finalI] = UriUtils.buildUri(this.host, rsp.documentSelfLink);
ctx.completeIteration();
});
this.host.send(createPost);
}
try {
// verify factory and service instance wiring.
factoryInstance.setHost(this.host);
Service serviceInstance = factoryInstance.createServiceInstance();
serviceInstance.setHost(this.host);
assertNotNull(serviceInstance);
ctx.await();
// do GET on all child URIs
Map<URI, ? extends ServiceDocument> childStates = this.host.getServiceState(null, serviceDocumentType, childURIs);
for (ServiceDocument s : childStates.values()) {
assertion.assertState(prefix, s);
}
// verify template GET works on factory
ServiceDocumentQueryResult templateResult = this.host.getServiceState(null, ServiceDocumentQueryResult.class, UriUtils.extendUri(factoryUri, ServiceHost.SERVICE_URI_SUFFIX_TEMPLATE));
assertTrue(templateResult.documentLinks.size() == templateResult.documents.size());
ServiceDocument childTemplate = Utils.fromJson(templateResult.documents.get(templateResult.documentLinks.iterator().next()), serviceDocumentType);
assertTrue(childTemplate.documentDescription != null);
assertTrue(childTemplate.documentDescription.propertyDescriptions != null && childTemplate.documentDescription.propertyDescriptions.size() > 0);
} catch (Throwable t) {
if (t instanceof RuntimeException) {
throw t;
}
throw new RuntimeException(t);
}
}
use of com.vmware.xenon.common.FactoryService in project photon-model by vmware.
the class BaseTestCase method verifyService.
protected void verifyService(Service factoryInstance, Class<? extends ServiceDocument> serviceDocumentType, TestServiceDocumentInitialization serviceDocumentInit, TestServiceDocumentAssertion assertion) throws Throwable {
URI factoryUri = UriUtils.buildFactoryUri(this.host, ((FactoryService) factoryInstance).createServiceInstance().getClass());
verifyService(factoryUri, (FactoryService) factoryInstance, serviceDocumentType, serviceDocumentInit, assertion);
}
Aggregations