Search in sources :

Example 16 with Namespace

use of io.kubernetes.client.proto.V1.Namespace in project scylla by bptlab.

the class SimulationConfigurationParser method parse.

@Override
public SimulationConfiguration parse(Element rootElement) throws ScyllaValidationException {
    Namespace simNamespace = rootElement.getNamespace();
    List<Element> simElements = rootElement.getChildren("simulationConfiguration", simNamespace);
    if (simElements.isEmpty()) {
        throw new ScyllaValidationException("No simulation configuration in file.");
    } else if (simElements.size() > 1) {
        throw new ScyllaValidationException("Multiple simulation configurations in file. If you want to simulate mulitple scenarios, then store them in separate simulation configuration files.");
    }
    Element sim = simElements.get(0);
    String processRef = sim.getAttributeValue("processRef");
    ProcessModel processModel = simulationEnvironment.getProcessModels().get(processRef);
    Long randomSeed = simulationEnvironment.getGlobalConfiguration().getRandomSeed();
    SimulationConfiguration simulationConfiguration = parseSimulationConfiguration(sim, simNamespace, processRef, processModel, randomSeed);
    // }
    return simulationConfiguration;
}
Also used : ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) SimulationConfiguration(de.hpi.bpt.scylla.model.configuration.SimulationConfiguration) Element(org.jdom2.Element) Namespace(org.jdom2.Namespace)

Example 17 with Namespace

use of io.kubernetes.client.proto.V1.Namespace in project scylla by bptlab.

the class BoundarySCParserPlugin method parse.

// Therefore this method should be called just once for a sim.xml file
@Override
public Map<String, Object> parse(SimulationConfiguration simulationInput, Element sim) throws ScyllaValidationException {
    Map<Integer, BranchingBehavior> branchingBehaviors = new HashMap<Integer, BranchingBehavior>();
    Namespace simNamespace = sim.getNamespace();
    ProcessModel processModel = simulationInput.getProcessModel();
    for (Element element : sim.getChildren()) {
        String elementName = element.getName();
        if (elementName.equals("task") || elementName.endsWith("Task") || elementName.equals("subProcess")) {
            String identifier = element.getAttributeValue("id");
            if (identifier == null) {
                DebugLogger.log("Warning: Simulation configuration definition element '" + elementName + "' does not have an identifier, skip.");
                // No matching element in process, so skip definition.
                continue;
            }
            Integer nodeId = processModel.getIdentifiersToNodeIds().get(identifier);
            if (nodeId == null) {
                DebugLogger.log("Simulation configuration definition for process element '" + identifier + "', but not available in process, skip.");
                // No matching element in process, so skip definition
                continue;
            }
            // Get the list of all corresponding boundary events.
            Element boundaryEventsElem = element.getChild("boundaryEvents", simNamespace);
            if (boundaryEventsElem != null) {
                List<Element> boundaryEventElements = boundaryEventsElem.getChildren("boundaryEvent", simNamespace);
                if (boundaryEventElements.size() > 0) {
                    Map<Integer, Double> probabilities = new HashMap<Integer, Double>();
                    double probabilityOfStandardFlow = 1;
                    for (Element elem : boundaryEventElements) {
                        // Collect probabilities of boundary event occurrence...
                        String id = elem.getAttributeValue("id");
                        Integer nodeIdOfBoundaryEvent = processModel.getIdentifiersToNodeIds().get(id);
                        if (nodeIdOfBoundaryEvent == null) {
                            throw new ScyllaValidationException("Simulation configuration refers to unknown boundary event: " + id);
                        }
                        // ... and subtract them from the default path behavior. The percentage of the default path is just
                        // relevant for interrupting events because its implicit 1 at tasks with only nn-interrupting events.
                        Element eventProbabilityElement = elem.getChild("eventProbability", simNamespace);
                        Double probabilityOfBoundaryEvent = Double.parseDouble(eventProbabilityElement.getText());
                        probabilityOfStandardFlow -= probabilityOfBoundaryEvent;
                        probabilities.put(nodeIdOfBoundaryEvent, probabilityOfBoundaryEvent);
                        // Add the arrival rate (= which is here the time at which the boundary event shall occur) relatively to the start of its task.
                        Element arrivalRateElement = elem.getChild("arrivalRate", simNamespace);
                        if (arrivalRateElement != null) {
                            TimeDistributionWrapper distribution = SimulationConfigurationParser.getTimeDistributionWrapper(arrivalRateElement, simNamespace);
                            // TODO: should be put into an extension attribute
                            simulationInput.getArrivalRates().put(nodeIdOfBoundaryEvent, distribution);
                        }
                    }
                    if (probabilityOfStandardFlow < 0) {
                        // The probability values of boundary events are added why they should not exceed 1 in total.
                        throw new ScyllaValidationException("Simulation configuration defines probabilities for boundary events of task " + identifier + ", exceeding 1 in total.");
                    }
                    /*else if (probabilityOfStandardFlow == 0) { // Does not happen anymore and should not happen semantically correct.
                            DebugLogger
                                    .log("Warning: Simulation configuration defines probabilities for boundary events of task "
                                            + identifier + ", but does not allow the normal flow to fire. \n"
                                            + "This may result in an infinite number of firings of boundary events "
                                            + "if none of them is interrupting.");
                        }*/
                    // XXX timer events do not have probabilities
                    // XXX probability of normal flow is stored under nodeId of task
                    // And save them for now.
                    probabilities.put(nodeId, probabilityOfStandardFlow);
                    BranchingBehavior branchingBehavior = new BranchingBehavior(probabilities);
                    branchingBehaviors.put(nodeId, branchingBehavior);
                }
            }
        }
    }
    // Store all branching behaviors collected for that task.
    HashMap<String, Object> extensionAttributes = new HashMap<String, Object>();
    extensionAttributes.put("branchingBehaviors", branchingBehaviors);
    return extensionAttributes;
}
Also used : ProcessModel(de.hpi.bpt.scylla.model.process.ProcessModel) HashMap(java.util.HashMap) BranchingBehavior(de.hpi.bpt.scylla.model.configuration.BranchingBehavior) Element(org.jdom2.Element) Namespace(org.jdom2.Namespace) ScyllaValidationException(de.hpi.bpt.scylla.exception.ScyllaValidationException) TimeDistributionWrapper(de.hpi.bpt.scylla.model.configuration.distribution.TimeDistributionWrapper)

Example 18 with Namespace

use of io.kubernetes.client.proto.V1.Namespace in project java by kubernetes-client.

the class ProtoExample method main.

public static void main(String[] args) throws IOException, ApiException, InterruptedException {
    ApiClient client = Config.defaultClient();
    Configuration.setDefaultApiClient(client);
    ProtoClient pc = new ProtoClient(client);
    ObjectOrStatus<PodList> list = pc.list(PodList.newBuilder(), "/api/v1/namespaces/default/pods");
    if (list.object.getItemsCount() > 0) {
        Pod p = list.object.getItems(0);
        System.out.println(p);
    }
    Namespace namespace = Namespace.newBuilder().setMetadata(ObjectMeta.newBuilder().setName("test").build()).build();
    ObjectOrStatus<Namespace> ns = pc.create(namespace, "/api/v1/namespaces", "v1", "Namespace");
    System.out.println(ns);
    if (ns.object != null) {
        namespace = ns.object.toBuilder().setSpec(NamespaceSpec.newBuilder().addFinalizers("test").build()).build();
        // This is how you would update an object, but you can't actually
        // update namespaces, so this returns a 405
        ns = pc.update(namespace, "/api/v1/namespaces/test", "v1", "Namespace");
        System.out.println(ns.status);
    }
    ns = pc.delete(Namespace.newBuilder(), "/api/v1/namespaces/test");
    System.out.println(ns);
}
Also used : PodList(io.kubernetes.client.proto.V1.PodList) Pod(io.kubernetes.client.proto.V1.Pod) ApiClient(io.kubernetes.client.ApiClient) Namespace(io.kubernetes.client.proto.V1.Namespace) ProtoClient(io.kubernetes.client.ProtoClient)

Aggregations

Element (org.jdom2.Element)17 Namespace (org.jdom2.Namespace)17 ProcessModel (de.hpi.bpt.scylla.model.process.ProcessModel)9 ScyllaValidationException (de.hpi.bpt.scylla.exception.ScyllaValidationException)7 HashMap (java.util.HashMap)7 BranchingBehavior (de.hpi.bpt.scylla.model.configuration.BranchingBehavior)3 NodeNotFoundException (de.hpi.bpt.scylla.model.process.graph.exception.NodeNotFoundException)3 Map (java.util.Map)3 TimeDistributionWrapper (de.hpi.bpt.scylla.model.configuration.distribution.TimeDistributionWrapper)2 CommonProcessElements (de.hpi.bpt.scylla.model.process.CommonProcessElements)2 MultipleStartNodesException (de.hpi.bpt.scylla.model.process.graph.exception.MultipleStartNodesException)2 NoStartNodeException (de.hpi.bpt.scylla.model.process.graph.exception.NoStartNodeException)2 MessageFlow (de.hpi.bpt.scylla.model.process.node.MessageFlow)2 SimulationManager (de.hpi.bpt.scylla.SimulationManager)1 DebugLogger (de.hpi.bpt.scylla.logger.DebugLogger)1 SimulationConfiguration (de.hpi.bpt.scylla.model.configuration.SimulationConfiguration)1 Distribution (de.hpi.bpt.scylla.model.configuration.distribution.Distribution)1 GlobalConfiguration (de.hpi.bpt.scylla.model.global.GlobalConfiguration)1 DynamicResource (de.hpi.bpt.scylla.model.global.resource.DynamicResource)1 DynamicResourceInstance (de.hpi.bpt.scylla.model.global.resource.DynamicResourceInstance)1