Signing up for Apple Developer Program on Windows

Problem

You would like to become an esteemed member of Apple’s Developer Program but you dare to do so from a machine running Microsoft Windows using Internet Explorer or Google Chrome.

After you click on either [Individual] or [Company] as shown below …

… you are greeted with an broken web page such as:

Solution

As I was told by the Apple support (with an amazing response time of 1 day!), you can only sign up using Apple’s Safari Browser.

So download the Safari browser for Windows and do the sign up there!

Possible Obstacles

Even using the Safari browser, I encountered a number of problems such as:

We’ll be back soon.

Or Can’t connect to application instance.

If this happens, don’t despair! Just try again later. Eventually, the planets will have the right constellation and the registration process will work!

 

 

OpsUnit Motivation and Plan (JUnit for server monitoring)

While the infrastructure for Appjangle and Nextweb has been humming along without any major problems, I have been thinking about ways to improve the long-time stability of the servers.

Being lazy in the sense that I dread any tasks, which I believe could be automated, I have created a few bash scripts on the cloud servers. These do some regular checks and restart the servers in periodic intervals.

Mainly, I seek to assure that the servers remain operational, even if no one is available to watch them.

However, the current solution is somewhat deficient, since with every server restart, there is a period of about 2 to 3 seconds, in which RPC calls and web requests are delayed.

Ideally, I would like to restart the servers only when it would be necessary to restart them (some unexpected error occurs), not all the time.

My plan is to build a simple monitoring process, which will do periodic checks of the deployed server infrastructure. In case any of the monitored services performs unsatisfactorily (low performance or no performance), this monitoring process should then perform some operations to restore the server (restart a component of the server or the OS level process if worst comes to worst).

While I am sure there are a number of solutions out there to achieve this, I am, as always, seeking something that is as lightweight as possible (JMX, for instance, in my view, is too heavyweight).

I will have a try at building a simple framework, which will utilize JUnit tests to do periodic checks on the server and then perform a set of simple actions, once one of the tests fails.
The basic architecture of the system is composed of the following components:

JUnit Test
These can be vanilla JUnit test cases, which perform actions on the cloud servers through the same means as a normal client would.
JUnit Test Runner
The unit tests can be run by a standard Junit test runner (The Text-based variant).
Response
A simple interface, such as Runnable, which allows to specify an action to be taken in case a unit test (executed by the test runner fails). Each response should also have an escalation level. Meaning that multiple responses can be chained and executed in order of increasing escalation (for instance from restart server component to restart server gracefully to kill server process 🙂 ).
Job
A periodical job, which will execute a number of JUnit test cases and run the appropriate responses as required. A job shall have the following properties:

  • A list of unit tests
  • A list of responses
  • An interval in which the job is to be executed

Job Runner
A simple manager, which will run the jobs as required by their specified intervals.

I’ve set up a github project, opsunit; but not much there yet. I think I will get to set up this framework in the next days.

Jenkins StackOverflow Exception during JUnit Test

Problem

The build of a Maven job in Jenkins fails due to a StackOverflowException or a OutOfMemoryException during a JUnit test.

Analysis

Most likely, there is a bug in your application, which leads to infinite recursion or an infinite allocation in resources. So first try to run your test in a different environment (for instance in eclipse, directly through Maven or as plain Java application).

However, sometimes, as in my case, the application works correctly and just requires more memory/stack size than is provided by the JVM during default settings. In this case, you will need to adjust the JVM settings in order to allow for more memory/stack size.

Solution

The JVM parameters, which allow to allocate more memory or stack size to a JVM are:

1. 

-Xss(x)m

where x is the size of the stack you would like to use. For instance: -Xss4m for a 4 MB stack size.

2.

-Xmx(x)m

where x is the size of the Java heap space (=memory) you would like to use. For instance: -Xmx1024m for a 1024 MB heap space.

Unfortunately, there are multiple places in which these parameters can be configured. Essentially, if the increased heap space requirement is in your application, you will need to adjust the parameters for the JUnit test runner in Maven:


<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-surefire-plugin</artifactId>
 <version>2.12.4</version>
 <configuration>
 <argLine>-Xss18m</argLine>
 </configuration>
 </plugin>

However, if the adjusted parameters are required for building your application, you might have to adjust them for the Maven Build Process.

This can be done by adding the parameters to MAVEN_OPTS either:

  • for your job: [Your Job] / Configure / Build / Advanced / MAVEN_OPTS
  • or for the Jenkins instance: Jenkins / Manage Jenkins / Configure System / Maven Project Configuration / Global MAVEN_OPTS

The last possible culprit might be the Jenkins server itself.

You can set the JVM parameters for Jenkins either by specifying them when:

  • starting Jenkins through java [your JVM parameters here] -jar jenkins.war or
  • by editing the jenkins.xml in your JENKINS_HOME folder.

Resources

Increasing Memory of junit Testcases

Stackoverflow – Jenkins build fails after running Cucumber tests on Java heap space exception

Increase heap size in java

Stackoverflow – How to give Jenkins more heap space when it´s started as a service under Windows?

 

Embedding Jenkins in Java App

The Continuous Integration server Jenkins can easily be deployed to any Servlet container or run in standalone mode (see Starting Jenkins).

However, sometimes it can be handy to be able to start Jenkins from within another Java application. I like this option since this ‘manager’ Java app can easily be deployed to other systems and platforms (without having to install Tomcat/Jetty etc). It is also useful to easily start Jenkins from an eclipse workspace (just run the Java file 🙂 ).

The only way I found to achieve this is to use Java to start anther OS process and then control Jenkins through this process.

Please find below example code to start a Jenkins process from a Java application. Don’t forget to change the paths and ports given as static variables in the beginning to your environment!


public class StartJenkins {

/**
 * Location of Jenkins executable
 */
 public static String JENKINS_WAR = "M:\\apps\\jenkins\\jenkins.war";

/**
 * Locations of Settings and Jobs
 */
 public static String JENKINS_HOME = "M:\\apps\\jenkins\\.jenkins";

/**
 * The Http port on which Jenkins web server shall be started.
 */
 public static String HTTP_PORT = "9090";

/**
 * The Https port on which Jenkins web server shall be started.
 */
 public static String HTTPS_PORT = "9999";

/**
 * AJP13 port for Jenkins.
 */
 public static String AJP13_PORT = "9003";

/**
 * @param args
 * @throws IOException
 */
 public static void main(final String[] args) throws IOException {
 final Process jenkins = startJenkinsProcess();

System.out.println("Press 'q' + enter to kill Jenkins");
 while (System.in.read() != Character.valueOf('q')) {
 System.out.println("Press 'q' + enter to kill Jenkins");
 }
 jenkins.destroy();
 System.out.println("Jenkins is done for!");
 }

public static Process startJenkinsProcess() {
 try {

final Runtime rt = Runtime.getRuntime();
 final Process proc = rt.exec("java -DJENKINS_HOME=" + JENKINS_HOME
 + " -jar " + JENKINS_WAR + " --httpPort=" + HTTP_PORT
 + " --httpsPort=" + HTTPS_PORT + " --ajp13Port="
 + AJP13_PORT);

final StreamRedirectorThread errorStreamProcessor = new StreamRedirectorThread(
 proc.getErrorStream(), "err", System.err);

final StreamRedirectorThread outputStreamProcessor = new StreamRedirectorThread(
 proc.getInputStream(), "out", System.out);

// start processors for output and error stream
 errorStreamProcessor.start();
 outputStreamProcessor.start();

return proc;

} catch (final Throwable t) {
 throw new RuntimeException(t);
 }

}

/**
 * based on <a
 * href="http://www.javaworld.com/jw-12-2000/jw-1229-traps.html?page=4">When
 * Runtime.exec() won't</a>
 *
 *
 */
 public static class StreamRedirectorThread extends Thread {
 InputStream is;
 String type;
 OutputStream redirect;

StreamRedirectorThread(final InputStream is, final String type,
 final OutputStream redirect) {
 this.is = is;
 this.type = type;
 this.redirect = redirect;
 }

@Override
 public void run() {
 try {
 PrintWriter redirectedWriter = null;

redirectedWriter = new PrintWriter(redirect);

final InputStreamReader isr = new InputStreamReader(is);
 final BufferedReader br = new BufferedReader(isr);
 String line = null;
 while ((line = br.readLine()) != null) {
 redirectedWriter.println(line);
 }

redirectedWriter.flush();

} catch (final IOException ioe) {
 ioe.printStackTrace();
 }
 }
 }

}