package au.edu.unsw.cse.soc.federatedcloud.orchestrator;
/*
 * Copyright (c) 2014, Denis Weerasiri All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import au.edu.unsw.cse.soc.federatedcloud.orchestrator.datamodel.workflow.OrchestratorWorkflow;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;

/**
 * User: denis
 * Test class to start the orchestrator engine and event generator
 */
public class TestClass {
    private static final Logger log = LoggerFactory.getLogger(TestClass.class);

    public static void main(String[] args) throws IOException {
        OrchestratorEngine engine = OrchestrationEngineHolder.getInstance().getOrchestratorEngine();
        engine.startOrchestrationEngine();

        OrchestratorWorkflow workflow = engine.buildOrchestratorWorkflow(new File("orchestration-engine/src/main/resources/sample-orchestration-workflow.json"));
        engine.deployOrchestratorWorkflow(workflow);

        engine.startEventGenerator();
    }
}

@@ -834,56 +834,222 @@
 ry;%0A
-%0Aimport java.io.File;%0Aimport java.io.IOException
+import sun.misc.BASE64Encoder;%0A%0Aimport javax.crypto.Mac;%0Aimport javax.crypto.spec.SecretKeySpec;%0Aimport java.io.File;%0Aimport java.io.IOException;%0Aimport java.security.SignatureException;%0Aimport java.util.Properties
 ;%0A%0A/
@@ -1243,20 +1243,23 @@
 lass);%0A%0A
+%0A
     
+/*
 public s
@@ -1718,7 +1718,2037 @@
    %7D
+*/%0A%0A    public static void main(String%5B%5D args) throws Exception %7B%0A        TestClass clazz = new TestClass();%0A        System.out.println(clazz.putBucket(%22Tue, 25 Feb 2014 07:20:23 +0000%22));%0A    %7D%0A%0A    public String putBucket(String date) throws Exception %7B%0A        //Reading the credentials%0A        String AWS_ACCESS_KEY = %22%22;%0A        String AWS_SECRET_KEY = %22%22;%0A%0A        String toSign = %22%22;%0A        /*%0A        toSign = %22PUT%22 + %22%5Cn%22 +%0A                ContentMD5 + %22%5Cn%22 +%0A                ContentType + %22%5Cn%22 +%0A                date + %22%5Cn%22 +%0A                CanonicalizedAmzHeaders +%0A                CanonicalizedResource;%0A*/%0A%0A        String signed = calculateRFC2104HMAC(toSign, AWS_SECRET_KEY);%0A%0A        return %22AWS %22 + AWS_ACCESS_KEY + %22:%22 + signed;%0A    %7D%0A%0A    /**%0A     * Computes RFC 2104-compliant HMAC signature.%0A     * * @param data%0A     * The data to be signed.%0A     *%0A     * @param key The signing key.%0A     * @return The Base64-encoded RFC 2104-compliant HMAC signature.%0A     * @throws java.security.SignatureException%0A     *          when signature generation fails%0A     */%0A    public String calculateRFC2104HMAC(String data, String key)%0A            throws java.security.SignatureException %7B%0A        String HMAC_SHA1_ALGORITHM = %22HmacSHA1%22;%0A        String result;%0A        try %7B%0A%0A            // get an hmac_sha1 key from the raw key bytes%0A            SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), HMAC_SHA1_ALGORITHM);%0A%0A            // get an hmac_sha1 Mac instance and initialize with the signing key%0A            Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);%0A            mac.init(signingKey);%0A%0A            // compute the hmac on input data bytes%0A            byte%5B%5D rawHmac = mac.doFinal(data.getBytes());%0A%0A            // base64-encode the hmac%0A            BASE64Encoder encoder = new BASE64Encoder();%0A            result = encoder.encode(rawHmac);%0A%0A        %7D catch (Exception e) %7B%0A            throw new SignatureException(%22Failed to generate HMAC : %22 + e.getMessage());%0A        %7D%0A        return result;%0A    %7D%0A%7D
 %0A
-%7D
 %0A

Test cases for orchestration tasks