Search in sources :

Example 16 with SystemAdaptation

use of org.iobserve.planning.systemadaptation.SystemAdaptation in project iobserve-analysis by research-iobserve.

the class systemadaptationExample method main.

/**
 * <!-- begin-user-doc -->
 * Load all the argument file paths or URIs as instances of the model.
 * <!-- end-user-doc -->
 * @param args the file paths or URIs.
 * @generated
 */
public static void main(String[] args) {
    // Create a resource set to hold the resources.
    // 
    ResourceSet resourceSet = new ResourceSetImpl();
    // Register the appropriate resource factory to handle all file extensions.
    // 
    resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new systemadaptationResourceFactoryImpl());
    // Register the package to ensure it is available during loading.
    // 
    resourceSet.getPackageRegistry().put(systemadaptationPackage.eNS_URI, systemadaptationPackage.eINSTANCE);
    // 
    if (args.length == 0) {
        System.out.println("Enter a list of file paths or URIs that have content like this:");
        try {
            Resource resource = resourceSet.createResource(URI.createURI("http:///My.systemadaptation"));
            SystemAdaptation root = systemadaptationFactory.eINSTANCE.createSystemAdaptation();
            resource.getContents().add(root);
            resource.save(System.out, null);
        } catch (IOException exception) {
            exception.printStackTrace();
        }
    } else {
        // 
        for (int i = 0; i < args.length; ++i) {
            // Construct the URI for the instance file.
            // The argument is treated as a file path only if it denotes an existing file.
            // Otherwise, it's directly treated as a URL.
            // 
            File file = new File(args[i]);
            URI uri = file.isFile() ? URI.createFileURI(file.getAbsolutePath()) : URI.createURI(args[i]);
            try {
                // Demand load resource for this file.
                // 
                Resource resource = resourceSet.getResource(uri, true);
                System.out.println("Loaded " + uri);
                // 
                for (EObject eObject : resource.getContents()) {
                    Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eObject);
                    if (diagnostic.getSeverity() != Diagnostic.OK) {
                        printDiagnostic(diagnostic, "");
                    }
                }
            } catch (RuntimeException exception) {
                System.out.println("Problem loading " + uri);
                exception.printStackTrace();
            }
        }
    }
}
Also used : SystemAdaptation(org.iobserve.planning.systemadaptation.SystemAdaptation) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) Diagnostic(org.eclipse.emf.common.util.Diagnostic) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) org.iobserve.planning.systemadaptation.util.systemadaptationResourceFactoryImpl(org.iobserve.planning.systemadaptation.util.systemadaptationResourceFactoryImpl) File(java.io.File) URI(org.eclipse.emf.common.util.URI)

Aggregations

SystemAdaptation (org.iobserve.planning.systemadaptation.SystemAdaptation)16 Test (org.junit.Test)12 ComponentNode (org.iobserve.adaptation.data.graph.ComponentNode)8 AdaptationData (org.iobserve.adaptation.data.AdaptationData)7 ExecutionPlan (org.iobserve.adaptation.executionplan.ExecutionPlan)7 DeploymentNode (org.iobserve.adaptation.data.graph.DeploymentNode)4 BlockRequestsToComponentAction (org.iobserve.adaptation.executionplan.BlockRequestsToComponentAction)3 ConnectComponentAction (org.iobserve.adaptation.executionplan.ConnectComponentAction)3 DeployComponentAction (org.iobserve.adaptation.executionplan.DeployComponentAction)3 DisconnectComponentAction (org.iobserve.adaptation.executionplan.DisconnectComponentAction)3 FinishComponentAction (org.iobserve.adaptation.executionplan.FinishComponentAction)3 MigrateComponentStateAction (org.iobserve.adaptation.executionplan.MigrateComponentStateAction)3 UndeployComponentAction (org.iobserve.adaptation.executionplan.UndeployComponentAction)3 AllocateAction (org.iobserve.planning.systemadaptation.AllocateAction)2 ChangeRepositoryComponentAction (org.iobserve.planning.systemadaptation.ChangeRepositoryComponentAction)2 DeallocateAction (org.iobserve.planning.systemadaptation.DeallocateAction)2 DereplicateAction (org.iobserve.planning.systemadaptation.DereplicateAction)2 MigrateAction (org.iobserve.planning.systemadaptation.MigrateAction)2 ReplicateAction (org.iobserve.planning.systemadaptation.ReplicateAction)2 Execution (teetime.framework.Execution)2