The Thing Device1 should be created properly and the property in DeviceMaster should be updated, even if the service fails at a later step. If this is not the behavior you want, I would recommend verifying that the DeviceNetwork exists before creating any Things meant for that Network or updating any properties. A single if statement outside of all your current logic should suffice. Hopefully this helps.
Rdhakrishnan, using Try-catch statements would help as well. When you have create Things on a script and it fails, it will lead to creation of ephemeral Things or 'ghost' entities. The only way at the moment to clear them would be to restart Tomcat. Here's an article that expands more on this topic.